线程间通讯

参考文章连接文章连接:http://www.codeproject.com/cpp/Win32_MQ_MultiThreading.asp

下边的事例程序用到了线程,test继承自CThread,参考下面的链接:

http://blog.csdn.net/wei801004/archive/2006/05/18/744341.aspx

 #define THRD_MESSAGE WM_USER + 2

DWORD WINAPI test::ThreadWorkItem(LPVOID lpParameter)
{
 MSG msg;
 while (true)
 {
  BOOL MsgReturn = ::PeekMessage(&msg, NULL, 0, 0,PM_REMOVE);//程序会立刻返回

 //BOOL MsgReturn = ::GetMessage(&msg, NULL, 0, 0);//程序阻塞接受消息

  if (MsgReturn)
  {
   switch ( msg.message )
   {
   case THRD_MESSAGE:
    {
     break;
    }
   default:
    cout<<"Error!"<<endl;
    break;
   }
  }
 }
 return 0;
}

int _tmain(int argc, _TCHAR* argv[])
{
 test oTest;
 oTest.Start();

 PostThreadMessage (oTest.m_dwThreadID, THRD_MESSAGE, 0,0);

 Sleep(100);
}

你可能感兴趣的:(user,null,通讯,winapi)