我的代码如下:
BOOL CMOThread::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_SERVER_ACCEPT)
{
AfxMessageBox("dd");
return TRUE;
}
return CWinThread::PreTranslateMessage(pMsg);
}在主线程中这样发消息:
CMOThread *myMO;
PostThreadMessage(myMO->MyThreadID,WM_SERVER_ACCEPT,wParam,lParam);
BOOL CMOThread::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_SERVER_ACCEPT)
{
AfxMessageBox("dd");
return TRUE;
}
return CWinThread::PreTranslateMessage(pMsg);
}在主线程中这样发消息:
CMOThread *myMO;
PostThreadMessage(myMO->MyThreadID,WM_SERVER_ACCEPT,wParam,lParam);
如
while (GetMessage(...))
{
}
#define WM_YOURMS WM_USER + 100
UINT YourWorkThread(LPVOID lpParameter)
{}
#define WM_YOURMS WM_USER + 100
UINT YourWorkThread(LPVOID lpParameter)
{
MSG msg;
while(PeekMessage(&msg,NULL, WM_USER, WM_USER, PM_NOREMOVE ))
{
if(msg.message == WM_YOURMS)
{
do something here
return 0;
}
}
return 1;
}
这样产生的消息队列默认只能接受10000个消息,而且不能调用DISPATCHMESSG函数,
如果你要重复接受消息,建议使用UI线程