线程里面怎么截获主窗体发送的消息?(64分)

D

difilwy

Unregistered / Unconfirmed
GUEST, unregistred user!

const
MY_ErrorMsg=WM_USER+1000;
type
TErrorMsg=record
ErrorId:integer;
ErrorStr:string;
end;

type
TErrorProcess = class(TThread)
private
{ Private declarations }
protected
procedure Execute;
override;
procedure OnSystemError(var msg:TErrorMsg);
message MY_ErrorMsg ;
end;
这样做怎么接受不到其他单元发出的消息?
 
在线程刚开始执行时,
In the thread to which the message will be posted,
call PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE)
to force the system to create the message queue.
上面是微软的Win32s SDK中的原文
调用 PeekMessage 强制系统创建线程的消息队列,否则,根本得不到消息的
 
to Lichaohui:不会用呀,能不能给个例子?谢谢
另外,帮助里面说PostThreadMessage好像可以,但是我每次调用的时候都回返回false,不只是什么原因
 
不是说得很清楚了吗?
需要先调用PeekMessage 创建线程的消息队列(线程默认是没有消息队列的)
然后就可以用GetMessage来获得消息了,
也可以用PostThreadMessage来发送消息了,
前提是指定线程的消息队列必须存在啊! 明白了吗? 朱头
 
费很大劲给你找的东西,你却不仔细看!!!
 
呵呵,现在很多人只要代码了,才不看你辛苦找到的资料了,衣来伸手,饭来张口也![:(]
 
to lichaohui:
我明白你说的意思,我也看过w32sdk,但是我不会用这个函数,没办法,水平太差。
如果你不想说就算了,不过没必要这么这么大火吧?根本没必要说什么“朱头”。一技
强如别人,没必要这么贬低别人!
 
在离线数据库中找到了peekmessage的用法,无论如何还是感谢你提出的信息,希望以后
不要这样打击别人。
 

Similar threads

I
回复
0
查看
502
import
I
S
回复
0
查看
691
SUNSTONE的Delphi笔记
S
I
回复
0
查看
609
import
I
顶部