Windows Message Queue

Source: Internet
Author: User

Gui thread:
When a thread creates a window or calls the GDI function, the system automatically creates a message queue.
There is nothing to say about it. There is no message loop and the window will not respond.

Non-Gui thread:
By default, no message queue is created. Calling getmessage forces the system to create a message queue.
Note the writing method here. If you write it like below,ProgramWill be suspended, because the new thread cannot guarantee
Get the call immediately, so the message queue of the subthread is not established, and the postmessage fails directly,

This message is also lost.

_ Stdcall Unsigned   Int Proc ( Void * P) {MSG; While (Getmessage (& MSG, null, 0, 0) {cout <msg. wparam <Endl ;} Return 0 ;} Int Main (Int Argc, Char * Argv []) { Unsigned ID; handle H1; H1 = (handle) _ beginthreadex (null, 0, Proc, null, 0, & ID ); If (0 = h1) {cout <" Fail "<Endl ;} Bool Res = False ; Int Num = 1; Res = postthreadmessage (DWORD) ID, wm_user, num, 0 ); If (Wait_failed = waitforsingleobject (H1, infinite) {cout <"Fail 2 "<Endl ;} Return 0 ;}

According to the description of msdn, the proper use of postthreadmessage is as follows:

 
BoolRes =False;While(! Res) {res = postthreadmessage (DWORD) ID, wm_user, 0, 0); sleep (1000 );}

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.