Article ID: 142415
Article Last Modified on 12/9/2003
/* Compile options needed:
standard MFC project generated by AppWizard */
BOOL CThreadMsgApp::PreTranslateMessage(MSG* pMsg)
{
// Is it the Message you want?
// You can use a switch statement but because this is
// only looking for one message, you can use the if/else
if (pMsg->message == WM_USER+2268)
{
// Call the function to handle this message
OnReceivedCommand(pMsg->wParam,pMsg->lParam);
// Tell MFC no more processing is needed
return TRUE;
}
else
// Call MFC to have it continue processing the message
return CWinThread::PreTranslateMessage(pMsg);
}
BOOL CThreadMsgApp::InitInstance()
{
WPARAM wParam;
LPARAM lParam;
wParam = MAKEWPARAM(0,0); // We can put whatever we
lParam = MAKELPARAM(0,0); // want in wParam & lParam
// Send the user-defined Thread Message
// m_nThreadID is a member of CWinThread that holds the thread ID
PostThreadMessage(m_nThreadID, WM_USER+2268, wParam, lParam);
return TRUE;
}
void CThreadMsgApp::OnReceivedCommand(WPARAM wParam, LPARAM lParam)
{
// You can do whatever you want in here, this is simply
// sending output to the debug window
TRACE0("Received WM_USER+2268!!\n");
}
Additional query words: 1.00 2.00 2.10 2.20 4.00 4.10
Keywords: kbthread kbprb KB142415