Basic knowledge
DECLARE_MESSAGE_MAP usage
DECLARE_MESSAGE_MAP ()
Explanation:
Each CCmdTarget derived class in your program can provide a message map to process messages. Use the DECLARE_MESSAGE_MAP macro at the end of your class declaration. Then, add the BEGIN_MESSAGE_MAP macro to the .CPP file that implements the class member functions, add the macro entry for each message processing function, and finally use the END_MESSAGE_MAP macro.
Note:
If you define members after DECLARE_MESSAGE_MAP, then you must specify a new access type (public, private, or protected) for them.
For more information on message mapping and the DECLARE_MESSAGE_MAP macro, see "Message Processing" and "Mapping Topics" in the "Visual C ++ Programmer's Guide."
Example:
// DECLARE_MESSAGE_MAP example
class CMyWnd: public CFrameWnd
{
// member declaration
DECLARE_MESSAGE_MAP ()
};
Explanation:
The role of the DECLARE_MESSAGE_MAP () macro is to add the necessary structure and function declarations for message mapping to the class. It only needs to be added once, and it does not matter where it is placed, just like the declaration of other ordinary functions in the class can be exchanged with each other. Function modifiers can also be determined by yourself, following general principles. For example, if you need to call the message response function outside the class, it can be defined as public.
======================================================= ====
In some materials, there is such a text:
DECLARE_MESSAGE_MAP ()
Explanation:
Each CCmdTarget derived class in the user program must provide a message map to process messages. Use the DECLARE_MESSAGE_MAP macro at the end of the class definition. Next, in the .CPP file that defines the class member functions, use the BEGIN_MESSAGE_MAP macro, the list under the macro item for each user message processing function, and the END_MESSAGE_MAP macro.
Notes:
If any members are defined after DECLARE_MESSAGE_MAP, they must be assigned a new access type (public, private, protected).
I think he described it incorrectly. My understanding is:
As long as it is: As long as it is a CCmdTarget (for all base classes capable of message mapping) derived class, there must be a message mapping to process messages, then the DECLARE_MESSAGE_MAP macro is at the end of the class description file, and the BEGIN_MESSAGE_MAP macro and END_MESSAGE_MAP are in the class definition file Macro to process user messages.
BEGIN_MESSAGE_MAP (parameter 1, parameter 2), parameter 1 is the class name of the class, parameter 2 is the class name of the base class of the class.
Among them, ON_MESSAGE (parameter 1, parameter 2), parameter 1 is the response message, and parameter 2 is the processing function name corresponding to the message.