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;
- }
Hi all!
I want to all of you know, World is mine, and yoursite good
G’night
Comment by GramBorder — March 20, 2007 @ 7:09 am
The site looks great ! Thanks for all your help ( past, present and future !)
Comment by morganusvitus — April 5, 2007 @ 6:16 pm
Excellent resource you\’ve got here!!! Will definately be back!!!t
Comment by mik — December 18, 2007 @ 11:27 pm
This is a Dynamic complete reference for VC++
Comment by Sudhakar Singh — March 7, 2008 @ 5:39 pm
You have an outstanding good and well structured site. I enjoyed browsing through it.
Comment by Timmy — November 29, 2008 @ 1:41 pm