1 #define WM_MYMSG1 WM_USER+1 2 #define WM_MYMSG2 WM_USER+2 3 4 HANDLE hThread; 5 //DWORD threadID1; 6 UINT threadID2; 7 8 //hThread=::CreateThread(NULL,0,lpFun,this,NULL,&threadID1); 9 hThread=(HANDLE)_beginthreadex( NULL, 0, &lpFun, NULL, NULL, &threadID2);//创建并启动线程 10 11 12 char * str="post message"; 13 PostThreadMessage(threadID1,WM_MYMSG1,(WPARAM)str,0);//向线程投递消息 14 15 16 17 UINT __stdcall lpFun(LPVOID lParam) 18 { 19 MSG msg; 20 PeekMessage(&msg, NULL, NULL, NULL,NULL); 21 while(TRUE) 22 { 23 if(GetMessage(&msg,0,0,0)) //get msg from message queue 24 { 25 char *str=(char*)msg.wParam; 26 CString strTemp=str; 27 switch(msg.message) 28 { 29 case WM_MYMSG1:AfxMessageBox(strTemp); 30 ;break; 31 case WM_MYMSG2:AfxMessageBox("2");break; 32 } 33 } 34 } 35 return 1; 36 }