CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  进程/线程/DLL

线程--------消息?????

楼主Elkel()2000-12-27 17:23:00 在 VC/MFC / 进程/线程/DLL 提问

我要用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

相关问题

  • 线程等待消息??
  • 多线程怎么取线程队列中消息?
  • 在其他线程中向主线程发消息的问题
  • 从线程向主线程发送消息出错,救命!
  • 在线程中如何接收消息?
  • 线程间发消息的问题
  • 在线程中处理消息
  • 关于线程消息的用法---------急
  • 线程结束后,有何消息呢???/
  • 线程消息问题,请帮帮忙~~

关键词

  • 线程
  • 消息
  • 函数
  • postthreadmessage
  • 处理
  • thread
  • posted
  • call
  • msg
  • message

得分解答快速导航

  • 帖主:Elkel
  • vcbear
  • zzh

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo