The problems encountered in the project have been solved but the reasons for time shortage have not been carefully considered.
Int winapi winmain (hinstance, hinstance, pstr strcommandline, INT)
{
.
// Blocking operation
Waitforsingleobject (g_event, inifinite );
Sendmessage (g_hmainwnd, wm_mainxxx, 0, 0 );
.
MSG;
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return 0;
}
Lresult callback mainwindowproc (hwnd, uint MSG, wparam W, lparam L)
{
Switch (MSG)
{
Case wm_threadxxx:
// Do -- something // No response. The message sent by the workerthread is not received. The response is normal.
Break;
Case wm_mainxxx:
// Do -- something // when the g_event event is received, the winmain message can be returned here.
Break;
}
Return defwindowproc (hwnd, MSG, W, L );
}
DWORD winapi workerthread (pvoid Arg)
{
// Send a message to the main window thread. At this time, winmain is still blocked.
// If sendmessage is used here, no response can be returned,
Postmessage (g_hmainwnd, wm_threadxxx, 0, 0 );
Return 0;
}
From the above analysis, I can conclude that:
(1) The difference between postmessage and sendmessage does exist.
Postmessage: only stores the message in the message pair column of the window line, regardless of whether the message is processed or not.
Sendmessage: it is returned only after the message is processed.
(2) wm_threadxxx cannot respond to workerthread because winmain has sent and sent messages.
Doubt:
Why is the message wm_mainxxx sent before message dispatch in winmain affected ??? At this time, there is no message loop.