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 );}