ClassWizard in the VC can process custom messages like processing other messages.
Below is the step of adding custom messages:
Step 1: Define messages in the application. When developing a Windows application, Microsoft recommends user-defined messages is WMUSER 100 because many new controls also use WM_USER messages.
Step 2: Implement the message processing function.
LpeSult CMAINFRAME :: ONMYMESSAGE (WPARAM WPARAM, LPARAM LPARAM)
{
// TODO: Handle 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_MAP
END_MESSAGE_MAP ()
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 is the same.
If you want to process schedule in the view in the multi-view program, you can use SendMessage in the MainFRM's ONTIMER, as shown in:
:: SendMessage (vhwnd, wm_demo_data, 0, 0);
Where vhwnd is the amount of HWND.
Vhwnd assigns a value in the ONCREATE of the view:
CMAINFRAME * PFRAME = (CMAINFRAME *) AFXGetApp () -> m_pmainwnd;
Pframe-> vhwnd = this-> m_hwnd;