MFC delivers messages with PostMessage

Source: Internet
Author: User
1. Customize the message ID.
#define Wm_my_message (wm_user+100) Wm_user is the ID reserved for the Windows system for non-system messages, at least 100, because messages from other controls take up part of the message.
2. Define the message handler function.
The message handler function is a member function of the message target class. It should first be declared in the. h file. Here, for example, the main window class, the main window class name Cmaindialog, the message handler function is declared first in CMainDialog.h.


Protected
afx_msg LRESULT onmymessage (WPARAM WPARAM, LPARAM LPARAM);



3. Implement message-handling functions in CMainDialog.cpp


Lpesult cmaindialog::onmymessage (WPARAM WPARAM, LPARAM LPARAM) {//TODO: Handling user custom Messages ... return 0;}
4. Mapping the message ID and message handler functions in CMainDialog.cpp


Begin_message_map (CMainFrame, CMDIFrameWnd)//{{afx_msg_map (CMainFrame) on_wm_create () On_wm_timer () on_message (WM_ My_message, OnMyMessage)//}}afx_msg_map End_message_map ()
When the thread is created, the main window handle is passed as a parameter to the thread, and the message can be delivered with PostMessage.









From for notes (Wiz)

MFC delivers messages with PostMessage

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.