如果有多個線程要更新主form的一些控件的信息, 想用消息傳送來統一處理, 也就是說,將線程要更新的東西,直接發消息到 Form , 然後, 由Form接收, 處理顯示的部分! 这必然要使用到postmessage了
定义我都有了,有哪位大哥共享一段源码阿,参考一下。 多谢阿,分不够可以再加,无所谓的。。
用PostMessage(FormHandle, WM_USER + 1, 0, integer(pchar(string)));
FormHandle可在線程創建的時候傳進去, 或用其它方法傳進去
WM_USER + 1 是自己定義的, 只要兩邊統一就好
0, 也可設成你需要的
string 就是你要傳的字符信息了
解决方案 »
- Dbgrid 按条件 显示颜色(字段属日期时间型的会出错)
- 如何编写代码,打开,读出,后缀名为SAV文件
- delphi用GET方法向WEB提交数据。谢谢
- 汕头delphi项目
- 请问各位大侠如何把数据库中的记录(自下而上滚动)显示出来
- 作过图形方面的高手,帮忙看看, 字体放大的算法,指点一下
- 帮忙搞软件测试. (高分回收BUG, 建议, BUG分析)
- 有关文本文件的操作
- 请教:DELPI的TABLE中如何按记录号范围删除记录
- public Tables: List<TableSchem> 语句如何转化为delphi6语句。
- 如何修改文本文件中以***开头的行中的数据?
- 急求DevExpress.ExpressQuantumGrid.Pro.3.2.1.with.source.for.Delphi7
WM_MYMSG = WM_USER+1;procedure WmTry(var msg: TMessage); message WM_MYMSG;procedure TForm1.WmTry(var msg: TMessage);
begin
if msg.WParam = 0 then
edit1.Text:= 'aaa';
end;procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(self.Handle,WM_MYMSG,0,1);
end;
begin if Message.WParam=0 then
{to do your handler at here}
else
inherited;
end;procedure TThread1.Execute;
begin
{to do your handler at here}
postMessage(Form1.Handle,0,1);
end;
WM_CUSTMSG=WM_USER+1024;procedure WndProc(var Message: TMessage); override;procedure WndProc(var Message: TMessage);
begin if Message.WParam=0 then
{to do your handler at here}
else
inherited;
end;procedure TThread1.Execute;
begin
{to do your handler at here}
postMessage(Form1.Handle,WM_CUSTMSG,0,1);
end;
其实可以就使用POSTTHREADMESSAGE
补充一点:
用POST一个消息方式来传递STRING之前,应该先把这个串的引用计数加一,
不然这个串所使用的内存空间在一些情况下会被释放掉。
WM_CLOSEFRAME=WM_USER + 109 ;{close Frame}
procedure TFrmMain.btnCloseClick(Sender: TObject);
begin
PostMessage(Application.Handle,WM_CLOSEFRAME,1,0) ;
end;
procedure TFrmMain.FormCreate(Sender: TObject);
begin
Application.OnMessage :=AppMessage;
end;
Procedure TFrmMain.AppMessage(Var msg:Tmsg;Var Handled:Boolean);
var i ,FrameCount:integer;
mnuItem:String;
mnuActive:TMenuItem;
begin
if msg.message=WM_CLOSEFRAME then
begin
for i:=0 to Screen.FormCount-1 do
if (Screen.Forms[i].Parent=pnlmain) and (Screen.Forms[i].Visible) then
begin
mnuItem :='mnuWin_'+Screen.Forms[i].Name ;
TMenuItem(FindComponent(mnuItem)).Free; mnuActive:=TMenuItem(FindComponent('mnuActive')) ;
if mnuActive.Count=2 then mnuActive.Free ; Screen.Forms[i].Free;
break;
end; FrameCount:=0;
For i:= 0 to Screen.FormCount-1 do
if Screen.Forms[i].parent=pnlmain then
begin
FrameCount:=1;
Screen.Forms[i].Show;
Break;
end; btnClose.Visible :=(FrameCount>0);
handled :=True;
end;
end;