1

我试图让上下文菜单适用于 CListCtrl 派生类。我刚刚创建了一个方法 OnContextMenu,但它没有被调用。我错过了什么?我正在使用 Visual Studio 2008 创建基于 CDialog 的 MFC 应用程序。

自定义列表.h

class tcCustomListCtl : public CListCtl
{
    DECLARE_DYNAMIC(tcCustomListCtl)

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

protected:
    DECLARE_MESSAGE_MAP()

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

自定义列表.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");
}
4

1 回答 1

2

我发现我必须将 ON_WM_CONTEXTMENU() 添加到消息映射中。

于 2010-02-05T15:57:19.550 回答