Using CHAIN_MSG_MAP_MEMBER with DefWindowProc

Viewed 132

Is there a way to use CHAIN_MSG_MAP_MEMBER with an uninitiated window class that calls DefWindowProc in one of its handler functions?

The problem is that if the member window class has not been created or subclassed, then its DefWindowProc is not going to work.

But what if you'd still like to try and chain its procedure as a member? Is there a workaround? Thank you for any help.

Here's an example of what I'm talking about. CChainedMember's call to DefWindowProc() will be useless, because m_wndChainedMember itself is never created or subclassed. It's just used for chaining purposes.

class CChainedMember : public CWindowImpl<CChainedMember>
{
public:

BEGIN_MSG_MAP(CChainedMember)
    MESSAGE_HANDLER(WM_CREATE, OnCreate)
END_MSG_MAP()

    LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL)
    {
       ATLTRACE(L"doing something before");
       DefWindowProc();
       ATLTRACE(L"doing something after");
       return 0;
    }
}

class CMainWindow : public CWindowImpl<CMainWindow>
{
public:

BEGIN_MSG_MAP(CMainWindow)
    CHAIN_MSG_MAP_MEMBER(m_wndChainedMember)
END_MSG_MAP()

CChainedMember m_wndChainedMember;

}

EDIT: Please disregard. I misunderstood the proper usage of CHAIN_MSG_MAP_MEMBER.

1 Answers

Any uninitialized member variable will cause this problem. You should construct members which will be used later in CMainWindow constructor or you just need a static method.

Related