Helpful Information
 
 
Category: .Net Development
ON_MESSAGE in C++.net

Has anyone managed to get ON_MESSAGE to work in MSVC++ .net? I've noticed lot's of help requests splattered across the web, but it seems no one knows how to make it work, since none of them get replies. Here's the old-fashioned way of doing it, works in MSVC++ 6.0.

In MainFrm.h


DECLARE_MESSAGE_MAP()
LRESULT OnMyMessage(LPARAM lParam, WPARAM wParam);

In MainFrm.cpp


#define UWM_MYMESSAGE (WM_USER + 1)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_MESSAGE(UWM_MYMESSAGE, OnMyMessage)
END_MESSAGE_MAP()

LRESULT CMainFrame::OnMyMessage(LPARAM lParam, WPARAM wParam)
{
return 0;
}

And the error:
...\MainFrm.cpp(30): error C2440: 'static_cast' : cannot convert from 'LRESULT (__thiscall CMainFrame::* )(LPARAM,WPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'

Why is this a problem now? Evidently, the framework doesn't like messages being handled outside of the CWnd class? It doesn't make sense, since you usually don't modify the CWnd class. CMainFrame is inherits from CWnd, so I don't see how the cast should be causing a problem. I've looked up the docs on c2440, but frankly, it's beyond me how that applies to MFC, since I'm not really familiar with the bowels of the MFC code.

How do you get WM_MESSAGE to work in c++.net?

i´m no c++ pro, but from my view:
CMainFrame should be a descendant of CWin, is it? so the declaration should be valid.

oooops, you switched LPARAM and WPARAM ;)

Wow, aren't I the fool? I knew it was something trivial. Hehehe...weeeeee!

I guess it's a good thing that the message map macros now catch bad prototypes, they never used to. Handy.










privacy (GDPR)--