afx_msg and message mapping mechanism

afx_msg macro statement is represented by a message response function

Message mapping mechanism is the core Windows programming. Applications are also under Windows to work through the mechanism of message-driven. Although VC development environment comes with a lot of system message processing function, but our actual total development process can not be avoided or write some custom message processing function to meet the needs of software functions written. So how do you define your own message handler in VC it? It comprises the following steps:

1, the user defines a message type identifier in the message header manner to define the class mapping functions defined by the macro. It is defined as follows: #define WM_USER1 WM_USER + 1 wherein WM_USER system is user defined message types. As long as this message is defined from the start point plus an offset value between 0 ~ 0x3FFF, and the system will not conflict with the definition of the other messages.

2. Right-click on the class, and then in the pop-up menu, select "Add Member Function" (Add member Function). In the pop-up dialog box to add a function of the type of function type input function box. Such as: afx_msg LRESULT message processing function must begin with afx_msg keyword indicating a global function. LRESULT is the type of the function. It indicates that the system is a callback function. It may also be other types. Such as int, void, and so legitimate data types. Enter the name of the function in the Function Name box. Such as: MyFunction (WPARAM wParam, LPARAM lParam), these two parameters are additional parameters for message delivery system. Beginning with W sixteen bits of information parameters. L is the beginning of thirty-two information parameters.

3, open the source file class. Find "BEGIN MESSAGE MAP" and "END MESSAGE MAP". Declaration message and message processing function therebetween. Such as: ON_MESSAGE (WM_USER1, MyFunction) .ON_MESSAGE user message is a system defined function mapping function. Preferably statement message mapping from the beginning to write "//}} AFX_MSG_MAP" next line, because it is a system maintenance marker automatically generated code. If you write on top of it, there may be deleted.

4, the function just defined message found in the source file class, writing implementation code.

5, where the message needs to be called by the mapping function SendMessage (WM_USER1); function call can be defined. WM_USER1 is the news we just defined name



Guess you like

Origin www.cnblogs.com/Stephen-Qin/p/12111945.html