How do I set up my own message in message map?
Hi,
I want to setup my own message (MM_REFRESH), and I don't know what exactly to do. Funny how none of my 5 books say anything on this.. hehe.
Anyways, I thought that I should enter
afx_msg void OnRefreshTerm();
to the message map in the header file. I then thought I should add ON_MM_REFRESH() to the message map in the cpp file.
What am I doing wrong here? I want MM_REFRESH to execute OnRefreshTerm().
Iwould also like to know what the proper way to call the message is. (ie this->SendMessage(MM_REFRESH, ???, ???);
Thanks
Re: How do I set up my own message in message map?
In the message map you should put:
ON_MESSAGE(MM_REFRESH, OnRefreshTerm)
HTH,
James Armstrong
Re: How do I set up my own message in message map?
MFC doesn't know about your message, so it's not going to have a pre-defined macro (#define) called ON_MM_REFRESH. Instead, you have to use ON_MESSAGE in your message map, like this:
ON_MESSAGE(MM_REFRESH, OnRefreshTerm)
If you are sending from the saying object (sending to "this"), then just call SendMessage(MM_REFRESH, ...). The other two parameters depend on what the function that handles the message expects for wParam and lParam.
Hope this helps,
Brad
Re: How do I set up my own message in message map?
The first thing you want to do is to place a constant that represents the message in the overall header file:
#define WM_REFRESH (WM_USER+1)
Next connect the message to the handler with the macro in the message map:
BEGIN_MESSAGE_MAP(.. , ..)
ON_MESSAGE(WM_REFRESH,OnRefresh())
END_MESSAGE_MAP()
Lastly, place prototype of OnRefresh in the class header and write the fuction itself.
Enjoy........
Re: How do I set up my own message in message map?