Question

How can be CHAIN_MSG_MAP_MEMBERused for two members ?
The example below works fine with a single listview and a single CHAIN_MSG_MAP_MEMBER. With both I have a crash.

class CMainFrame : public CFrameWindowImpl<CMainFrame>, public CUpdateUI<CMainFrame>,
        public CMessageFilter, public CIdleHandler
{
public:
    DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)

    virtual BOOL PreTranslateMessage(MSG* pMsg)
    {
        return CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg);
    }

    BEGIN_MSG_MAP(CMainFrame)
        MESSAGE_HANDLER(WM_CREATE, OnCreate)
        COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
        COMMAND_ID_HANDLER(ID_FILE_NEW, OnFileNew)
        COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
        CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
        CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
        CHAIN_MSG_MAP_MEMBER(m_listView)            //< 
        CHAIN_MSG_MAP_MEMBER(m_listView2)           //< ISSUE: crash with both, works with one.
    END_MSG_MAP()

    LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
    {
         // create a list box   
        RECT r = {0,0,182,80};    
        m_listView.Create(m_hWnd,r,CListViewCtrl::GetWndClassName(),WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | LVS_REPORT, WS_EX_CLIENTEDGE    );

        RECT r2 = {0,80,182,80+80};    
        m_listView2.Create(m_hWnd,r2,CListViewCtrl::GetWndClassName(),WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | LVS_REPORT, WS_EX_CLIENTEDGE    );

        ...

        populate

    }
} 

class MyListView : public CWindowImpl<MyListView, CListViewCtrl>,
                   public CCustomDraw<MyListView>                   
{
public:

  BEGIN_MSG_MAP(MyListView)    
    CHAIN_MSG_MAP(CCustomDraw<MyListView>)
    END_MSG_MAP()           

    DWORD OnPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW lpNMCustomDraw)
    {       
        ...
    }

    DWORD OnItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW lpNMCustomDraw)
    {
        ...
    }

    DWORD OnSubItemPrePaint(int /*idCtrl*/, LPNMCUSTOMDRAW lpNMCustomDraw)
    {
        ...
    }
    ............
}
Was it helpful?

Solution

CCustomDraw is WTL class and assumes you use BEGIN_MSG_MAP_EX, as opposed to ATL's BEGIN_MSG_MAP.

#include <atlcrack.h>

class MyListView : public CWindowImpl<MyListView, CListViewCtrl>,
                   public CCustomDraw<MyListView>                   
{
public:

BEGIN_MSG_MAP_EX(MyListView) // <<--- Here we go   
    CHAIN_MSG_MAP(CCustomDraw<MyListView>)
END_MSG_MAP()           

};

The rule of thumb is to never use BEGIN_MSG_MAP at all as long as you leverage WTL.

Also, it is worth to mention that this use of CHAIN_MSG_MAP_MEMBER makes no sense to me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top