In MFC, using user-defined messages, child windows Send message procedures, code to the parent window:
1 Add the definition in resourse.h:
#define WM_ADD_EVENT_OK (wm_user + 100)//This definition method is not tested, do not know how to do;
static UINT Wm_add_event_ok = RegisterWindowMessage (_t ("User"));//tested, feasible.
2 in the parent window, in the. h file, add the definition:
Protected
afx_msg lresult Onadd_event_ok (WPARAM WPARAM, LPARAM LPARAM);
Two parameters: WPARAM WPARAM, LPARAM LPARAM type cannot be changed.
3 Add the Message Mapping section in the parent window's. cpp file:
On_message (WM_ADD_EVENT_OK, ONADD_EVENT_OK)//No test, do not know whether feasible;
On_registered_message (WM_ADD_EVENT_OK,ONADD_EVENT_OK)//test pass, feasible.
4 defines the implementation of the message handler function in the parent window's. CPP:
LRESULT class Name:: Onadd_event_ok (WPARAM WPARAM, LPARAM LPARAM)
{
int c=10;
return 0;
}
5 use code when you need to send a message:
WPARAM a=8;
LPARAM b=9;
GetParent ()->sendmessage (WM_ADD_EVENT_OK,A,B);
Or send a message using the following code:
HWND hwnd =:: GetParent (M_hwnd);
:: SendMessage (HWND,WM_ADD_EVENT_OK,A,B);
SendMessage (WM_ADD_EVENT_OK,A,B)//In the test, when the GetParent ()-> is not used, the message cannot be delivered to the message handler function of the parent window, and only after the GetParent ()-> is added, The message can be sent successfully.