Each work you have to do for a Windows application is almost messaging, and Windows system messages are divided into common Windows messages, control notification messages, and commands. However, sometimes we need to define your own news to notify the program what happened, this is the user-defined message. ClassWizard does not provide the ability to increase user-defined messages, so use user-defined messages must be handled manually. The ClassWizard can then process your custom message like processing other messages. The specific practice is detailed below:
Step 1: Define the message. When a message is actually developing a Windows 95 application, Microsoft recommends user-defined messages at least WM_USER 100 because many new controls should also use WM_USER messages.
Step 2: Implement the message processing function. This function uses WPRAM and LPARAM parameters and returns lpeSult.
LPESULT CMAINFRAME :: OnmyMessage (WPARAM WPARAM, LPARAM LPARAM) {// Todo: Handling User Custom Messages AFXMESSAGEBOX ("Process User Custom Message"); Return 0;
Step 3: Describe the message processing function in the AFX_MSG block of the class header:
Class CMAINFRAME: PUBLIC CMDIFRAMEWND {
...
// General message mapping function
protected:
// {{AFX_MSG (CMAINFRAME)
AFX_MSG Int Oncreate (LPCReatestruct LPCreateStruct);
AFX_MSG Void Ontimer (uint nidEvent);
AFX_MSG LRESULT ONMYMESSAGE (WPARAM WPARAM, LPARAM LPARAM);
//}} AFX_MSG
Declare_MESSAGE_MAP ()}
Step 4: In the user class message block, use the ON_MESSAGE macro to map the message to the message processing function.
Begin_MESSAGE_MAP (CMAINFRAME, CMDIFRAMEWND)
// {{AFX_MSG_MAP (CMAINFRAME)
ON_WM_CREATE ()
ON_WM_TIMER ()
ON_MESSAGE (WM_MY_MESSAGE, ONMYMESSAGE)
//}} AFX_MSG_MAPEND_MESSAGE_MAP ()
In this way, a user-defined message can be used, if the user needs a unique message throughout the system, you can call the SDK function REGISTERWINDOWMESAGE and use the on_register_message macro to replace the ON_MESSAGE macro, the rest of the steps.
VC provides programmers with a set of powerful, convenient programming tools, which can help you generate a window, menu and other user interfaces, but unfortunately, it is the same, there is no personality. Here, you will introduce some methods, let us make more in line with your own program style window according to your design.