change message handler prototype's name
-
hello everyone, This is a kind of strange question but it just got stuck to me this morning while writing my MFC application. Every time we define a message macro in MESSAGE MAP, we use default prototype for handling that message, i.e. for handling WM_CHAR() message we have OnChar() handler, what i want to know is whether there's a way change this default handler and provide our own message handler, with our defined name.......... I know we can work around this by calling our defined function in the default message handler but what i want is i don't want to mention the default handler in my application code. your help is highly awaited........ thanks in advance Regards
-
hello everyone, This is a kind of strange question but it just got stuck to me this morning while writing my MFC application. Every time we define a message macro in MESSAGE MAP, we use default prototype for handling that message, i.e. for handling WM_CHAR() message we have OnChar() handler, what i want to know is whether there's a way change this default handler and provide our own message handler, with our defined name.......... I know we can work around this by calling our defined function in the default message handler but what i want is i don't want to mention the default handler in my application code. your help is highly awaited........ thanks in advance Regards
Yes you can add your own message handler for that. Firstly remove OnChar() function from MESSAGE MAP and remove all entries related to it. then just add the ON_MESSAGE for WM_CHAR in .cpp file BEGIN_MESSAGE_MAP(CMDI_CharView, CEditView) //{{AFX_MSG_MAP(CMDI_CharView) //}}AFX_MSG_MAP ON_MESSAGE( WM_CHAR, MyOnCharMessageHandlerFunction ) END_MESSAGE_MAP() and in .h file add your message handler function. protected: //{{AFX_MSG(CMDI_CharView) //}}AFX_MSG afx_msg void MyOnCharMessageHandlerFunction (UINT nChar, UINT nRepCnt, UINT nFlags); DECLARE_MESSAGE_MAP() :)
Величие не Бога может быть недооценена.
-
Yes you can add your own message handler for that. Firstly remove OnChar() function from MESSAGE MAP and remove all entries related to it. then just add the ON_MESSAGE for WM_CHAR in .cpp file BEGIN_MESSAGE_MAP(CMDI_CharView, CEditView) //{{AFX_MSG_MAP(CMDI_CharView) //}}AFX_MSG_MAP ON_MESSAGE( WM_CHAR, MyOnCharMessageHandlerFunction ) END_MESSAGE_MAP() and in .h file add your message handler function. protected: //{{AFX_MSG(CMDI_CharView) //}}AFX_MSG afx_msg void MyOnCharMessageHandlerFunction (UINT nChar, UINT nRepCnt, UINT nFlags); DECLARE_MESSAGE_MAP() :)
Величие не Бога может быть недооценена.
ARJ 09 wrote:
afx_msg void MyOnCharMessageHandlerFunction (UINT nChar, UINT nRepCnt, UINT nFlags);
Just a correction... The handler of the ON_MESSAGE should be in the format
LRESULT MyOnCharMessageHandlerFunction(WPARAM wParam, LPARAM lParam);
-
ARJ 09 wrote:
afx_msg void MyOnCharMessageHandlerFunction (UINT nChar, UINT nRepCnt, UINT nFlags);
Just a correction... The handler of the ON_MESSAGE should be in the format
LRESULT MyOnCharMessageHandlerFunction(WPARAM wParam, LPARAM lParam);
Yes exactly, thanks naveen for correcting me :)
Величие не Бога может быть недооценена.