2010-02-05 28 views
1

工作我想获取上下文菜单为CListCtrl派生类工作。我刚刚创建了一个方法OnContextMenu,但它没有被调用。我错过了什么?我正在使用Visual Studio 2008创建基于CDialog的MFC应用程序。无法获取OnContextMenu为自定义CListCtl类

CustomList.h

class tcCustomListCtl : public CListCtl 
{ 
    DECLARE_DYNAMIC(tcCustomListCtl) 

public: 
    tcCustomListCtl(); 
    virtual ~tcCustomListCtl(); 

protected: 
    DECLARE_MESSAGE_MAP() 

    afx_msg void OnContextMenu(CWnd* pWnd,CPoint pos); 
}; 

CustomList.cpp

// tcFaultListCtl 
IMPLEMENT_DYNAMIC(tcCustomListCtl, CListCtrl) 

tcCustomListCtl::tcCustomListCtl() 
{ 
} 

tcCustomListCtl::~tcCustomListCtl() 
{ 
} 

BEGIN_MESSAGE_MAP(tcCustomListCtl, CListCtrl) 
END_MESSAGE_MAP() 

// tcCustomListCtl message handlers 
afx_msg void tcCustomListCtl::OnContextMenu(CWnd* pWnd,CPoint pos) 
{ 
    TRACE("tcCustomListCtl::OnContextMenu\n"); 
} 

回答

2

我发现我不得不ON_WM_CONTEXTMENU()添加到消息映射。

相关问题