Reputation: 117
In gui app there is ON_MESSAGE(id, handler) with hanler's LRESULT CMainFrame::handler(WPARAM wParam, LPARAM lParam)
declaration.
Well, visial studio doesn't want to get such handler in ON_COMMAND(). What can I do to use the same hanler in ON_MESSAGE and in ON_COMMAND?
Thanks in advance.
Upvotes: 0
Views: 1148
Reputation: 926
as you noticed the handlers need different declarations to work for the ON_MESSAGE and the ON_COMMAND so you can't have the same function for both ON_COMMAND and ON_MESSAGE. you will have to create one function for each handler and then you can encapsulate your code into another function that is called from the first handlers.
like:
BEGIN_MESSAGE_MAP(CMyClass, CMyParentClass)
//{{AFX_MSG_MAP(CMyClass)
ON_MESSAGE(ID_MY_MESSAGE_ID,OnMyMessage)
ON_COMMAND(ID_MY_COMMAND_ID,OnMyCommand)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LRESULT CMyClass::OnMyMessage(WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(wParam);
UNREFERENCED_PARAMETER(lParam);
MyEncapsulatedCode();
return 0;
}
void CMyClass::OnMyCommand()
{
MyEncapsulatedCode();
}
void CMyClass::MyEncapsulatedCode()
{
//do stuff
}
Upvotes: 1