线程消息收发

接受

代码
BOOL bRunning=TRUE;
 
while(bRunning)
 {
  MSG msg;
  DWORD dwRet 
= MsgWaitForMultipleObjects(0,NULL,FALSE,INFINITE,QS_ALLINPUT);
  
if (dwRet != WAIT_OBJECT_0) //退出
  {
   
break;
  }

  
while(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
  {  
   
if(!GetMessage(&msg,NULL,0,0) )
   {
    bRunning 
= FALSE;
    
break;
   }

   
if (msg.message == WM_USER + 1)
   {
    DWORD dwID
= msg.wParam;

   }
   
else
   {
    TranslateMessage(
&msg);
    DispatchMessage(
&msg);
   }
  }
  
 }

 

 发送

PostThreadMessage(m_dwThreadID,WM_USER+1,dwIP,NULL);

posted @ 2009-12-15 16:36  ahuo  阅读(278)  评论(0编辑  收藏  举报