Send message to thread

Source: Internet
Author: User
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 .)

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.