VC++ implements custom message

Mfc generally handles messages from Windows itself, if necessary, custom messages can also be implemented;

Create a new dialog box project; add a button;
define a message in Resource.h, the identifier is WM_MYMSG; custom messages start from WM_USER;

Define a message processing function mymsghandler in the dialog box header file; afx_msg macro means that the declaration is a message response function;

In the cpp file, between the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP macros, use the ON_MESSAGE() macro to add message mapping; ON_MESSAGE (message identification, message processing function);

To implement the message processing function, here is just a dialog box;

In the place where the message is triggered, use the SendMessage function to send the message; here it is sent when the button is clicked;

Add a click processing function to the button and send a custom message in it;

Click the button, receive the message, call the message processing function; as shown in the figure below;

 

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/114471597