Discussion:
Derived class and SendMessage
(too old to reply)
DanB
2013-02-07 19:45:35 UTC
Permalink
Maybe someone has seen this before and just knows, I can't figure it so far.

So I have a class derived from CFrameWnd
class HERichFrame : public CFrameWnd

And then in a test app I derive like:
class CMainFrame : public HERichFrame


I want HERichFrame to handle certain things internally. So it has:

ON_MESSAGE( ID_VIEWSCROLL, OnViewScroll )
afx_msg LRESULT OnViewScroll( WPARAM par, LPARAM );

.cpp
LRESULT HERichFrame::OnViewScroll( WPARAM param, LPARAM )
{
return FALSE;
}

but OnViewScroll never gets called. Yet I can add the exact same handler
to CMainFrame and it does get called, so it should not be about my
handler or ID.

ON_MESSAGE( ID_VIEWSCROLL, OnViewScroll )
afx_msg LRESULT OnViewScroll( WPARAM par, LPARAM );

.cpp
LRESULT CMainFrame::OnViewScroll( WPARAM param, LPARAM )
{
return FALSE;
}


The call is from the child view.
GetParent( )->SendMessage( ID_VIEWSCROLL, nPos );


Baffled, Best, Dan.
ScottMcP [MVP]
2013-02-07 20:58:48 UTC
Permalink
Check the class names that are in all of your BEGIN_MESSAGE_MAP statements. Those class names define the class derivation relationship for the message dispatching code. So in this statement:

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

any message not handled by the CAboutDlg message map will be passed down to the CDialog message map.
DanB
2013-02-07 23:13:01 UTC
Permalink
Post by ScottMcP [MVP]
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
any message not handled by the CAboutDlg message map will be passed down to the CDialog message map.
Hi Scott,
I thought of that and have. But it made me start to think and:
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CrtfParseDoc),
RUNTIME_CLASS(HERichFrame ),
RUNTIME_CLASS(CrtfParseView));

Instead of CMainFrame still had the problem. So the only thing I could
come up with was the:

#define ID_VIEWSCROLL ( WM_APP + 100 )

And found a second ID_VIEWSCROLL that didn't show on a search, or as a
warning, but with a different number! But when I opened that
'resource.h', it was there. That resource was a third resource in my
global includes, it should not have been there, I renamed it as
'junk.h'. What should have been my one and only define in globals should
have been in my 'heres.h'.

BTW, all my #include "resource.h" where that and not #include
<resource.h>, so I'm not sure why it got dug up.

Now that I ditched that extra resource.h it works fine.

Thanks for your time.

Best, Dan.

Loading...