Use postthreadmessage.
Bool postthreadmessage (
DWORD
Idthread , // Thread ID, ID after the thread is created
Uint
MSG , // Message ID
Wparam
Wparam ,
Lparam
Lparam ); Then, the thread obtains the message through getmessage or peekmessage.
CodeThe snippets are as follows:
Unsigned int callback thread_func (lpvoid LP ){ While (1) { MSG; While (getmessage (& MSG, null, 0, 0 )) // While (peekmessage (& MSG, null, 0, 0, pm_remove )) { Switch (msg. Message) { Case wm_mymessage: Printf ("\ n * thread_func1: % d", MSG. wparam ); Break; } } } The sending thread segment is as follows: Uint dwid _ Beginthreadex (null, 0, thread_func, null, 0, & dwid );... appendix: getmessage (lpmsg, hwnd, uint wmsgfiltermin, uint wmsgfiltermax) peekmessage (lpmsg, hwnd, uint average, uint wmsgfiltermax, uint wremovemsg) the wremovemsg parameter specifies the message retrieval method. If it is set to pm_noremove, the message will not be removed from the message queue. If it is set to pm_remove, the message will be removed from the message queue. The two functions have the following two differences: 1. getmessage will not be returned until there is a suitable message, while peekmessage is just a glimpse of the message queue. (Getmessage is suspended, while peekmessage is returned regardless of whether there are any messages.) 2. getmessage deletes the message from the queue, while peekmessage can set the last parameter wremovemsg to determine whether to keep the message in the queue. (If it is retained in the queue, it is best to process it immediately) in windows, getmessage and peekmessage execute the same code. The biggest difference between the two is that no message is returned to the application. Program . In this case, peekmessage returns a null value to the application, and getmessage will sleep the application at this time. (If it is used in the thread, it doesn't matter if getmessage or peekmessage is used. You don't need to consider the remove of the Message Queue. The message queue is just a copy in each thread? Only .)