执行完一段代码后,如何让多个窗口更新显示? ( 积分: 38 )

  • 主题发起人 g60sl22c
  • 开始时间
G

g60sl22c

Unregistered / Unconfirmed
GUEST, unregistred user!
我用多个窗口来显示处理对象的各种不同数据及结果.窗口数也是未知的,要视乎使用者打开多少个观察窗.执行完一段代码后,如何触发所有观察窗更新显示呢?怎样发更新消息,各窗口又如何接收呢?窗口数是不定的
 
我用多个窗口来显示处理对象的各种不同数据及结果.窗口数也是未知的,要视乎使用者打开多少个观察窗.执行完一段代码后,如何触发所有观察窗更新显示呢?怎样发更新消息,各窗口又如何接收呢?窗口数是不定的
 
[red][/red]实际上可用信号量或等待事件,设置一个更新事件tevent和窗口tlist和响应事件计数器c,存储窗口的handle,是否响应事件。当有数据时,event.setevent且c=窗口数,窗口查询event的状态(若用线程则用waitfor)响应该事件后设置对应handleflag为是,计数器减1,当计数器为0时event.reset(清除事件)
 
可否考虑“观察者模式”?
 
什么是“观察者模式”
 
Google
observer 设计模式
 
我想了个通过消息来更新内容的办法.但编译错误
以下是bcb帮助文件的内容
TMessage Msg;
Msg.Msg = MY_MYCUSTOMMESSAGE;
Msg.WParam = 0;
Msg.LParam = (int)(this);
Msg.Result = 0;
then
, pass this message structure to the parent of all the controls you want to notify. This can be any control in the application. For example, it can be the parent of the control you are writing:
Parent->Broadcast(Msg);
It can be the form that contains your control:
GetParentForm(this)->Broadcast(Msg);
It can be the active form:
Screen->ActiveForm->Broadcast(Msg);
It can even be all the forms in your application:
for (int i = 0;
i < Screen->FormCount;
i++)
Screen->Forms->Broadcast(Msg);
我根据此说明写成
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// SendMessage(HWND_BROADCAST, WM_SENDINFO, 0, 0);// Handle
TMessage Msg;
Msg.Msg = WM_SENDINFO;
Msg.WParam = 0;
Msg.LParam = (int)(this);
Msg.Result = 0;
for (int i = 0;
i < Screen->FormCount;
i++)
Screen->Forms->Broadcast(Msg);
}
编译过不了,'Mwessage'(want'void*',got 'TMessage')
何解?
 
基类实现刷新
派生类都具有刷新功能
 
用得着这么麻烦吗, 使用如下代码即可:
for (int i = 0;
i < Screen->FormCount;
i++)
Screen->Forms->Update();
}
 
要想编译通过, 将
Screen->Forms->Broadcast(Msg);
更改为
Screen->Forms->Broadcast(static_cast<void *>(&amp;Msg));
即可
 
多人接受答案了。
 
顶部