线程--------消息?????
我要用atl编写winnt服务程序,不能用mfc.....真是命苦啊,CWinThread不能用
我需要创建一个线程,能处理消息,我该怎么做???
问题点数:50、回复次数:7Top
1 楼sxbyl(sxbyl)回复于 2000-12-27 17:35:00 得分 0
建一个隐藏的Window??Top
2 楼panda_w(好想睡啊!)回复于 2000-12-27 17:48:00 得分 0
看来也只能这样了,没有窗口,不能处理消息的。Top
3 楼AtCsdn()回复于 2000-12-27 17:56:00 得分 0
错了!
消息队列是以线程为单位分配的,每个线程都有自己的消息队列;
你只要在线程函数中建立自己的消息循环就可以了!Top
4 楼vcbear(http://vcbear.mblogger.cn)回复于 2000-12-27 18:06:00 得分 30
AtCsdn是对的。
win32编程里,可以CreateThread(....
&idThread);
PostThreadMessage(idThread....
MSDN的说明了如何在Thread里处理消息:
Remarks
The thread to which the message is posted must have created a message queue, or else the call to PostThreadMessage fails. Use one of the following methods to handle this situation:
Call PostThreadMessage. If it fails, call theSleep function and call PostThreadMessage again. Repeat until PostThreadMessage succeeds.
Create an event object, then create the thread. Use theWaitForSingleObject function to wait for the event to be set to the signaled state before calling PostThreadMessage. 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. Set the event, to indicate that the thread is ready to receive posted messages.
The thread to which the message is posted retrieves the message by calling the GetMessage or PeekMessage function. The hwnd member of the returned MSG structure is NULL
Top
5 楼vcbear(http://vcbear.mblogger.cn)回复于 2000-12-27 18:06:00 得分 0
你的水平看E文没有问题吧。很明白的。Top
6 楼zzh()回复于 2000-12-27 18:13:00 得分 20
你使用SDK来进行写程序,利用CreateThread()来创建线程,使用AfxBeginThread()来开始一个线程的运行,然后在线程中处理消息。可以发送线程消息,使用函数,PostThreadMessage()至于这几个函数的具体参数,可以参考MSDN。应该不会有问题吧!Top
7 楼Elkel()回复于 2000-12-28 10:43:00 得分 0
消息环是否这样:
while(TRUE)
{
PeekMessage(&msg,-1,0,0,PM_REMOVE);
TranslateMessage(&msg);
WaitMessage();
}
我怎么处理消息????
Top




