WTL how to use 2 custom CListViewCtr drawings in the same window

How can I use CHAIN_MSG_MAP_MEMBERfor two participants?
The example below works fine with one list and one CHAIN_MSG_MAP_MEMBER. I am having a failure.

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)
    {
        ...
    }
    ............
}
+3
source share
1 answer

CCustomDrawis a WTL class and assumes that you are using BEGIN_MSG_MAP_EX, unlike ATL 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()           

};

Basic rule: never use BEGIN_MSG_MAPat all while you use WTL.

In addition, it is worth mentioning that this use CHAIN_MSG_MAP_MEMBERdoes not make any sense to me.

+4
source

All Articles