Few days back I received an email asking a question, here is it all with my answer
Qst
Can you tell me if I use the following
AfxGetMainWnd()->SendMessage(MY_MESSAGE, 0,(LPARAM) pValue);
The above message is sent to the parent window The message handler is
- LRESULT MyParent::OnMyMessage(WPARAM wParam, LPARAM lParam )
- {
- *(int *) lParam = 123;
- return 0;
- }
- return 0;
then can I make Message map of the form MY_MESSAGE and have a handler function OnMyMessage ? Since message maps are something that are provided by Windows API and they can be generated through Class Wizard where messages and their corresponding functions are already given. Ex WM_KEYDOWN with function OnKeyDown() Where should I map if (MY_MESSAGE) call OnMyMessage();
My Answer
As long as I understood the situation is you want to add a message handler for your own custom message.
#define WM_MYMESSAGE (WM_USER + 100)
in the header file just have this
afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
in cpp file do this
- BEGIN_MESSAGE_MAP(CMyWnd, CMyParentWndClass)
- ON_MESSAGE(WM_MYMESSAGE, OnMyMessage)
- END_MESSAGE_MAP()
- LRESULT MyParent::OnMyMessage( WPARAM wParam, LPARAM lParam )
- {
- // do what ever you wnat to do
- *(int *)lParam = 123;
- return 0;
- }