Win32 message loop

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.