【问题标题】:Can't get OnContextMenu to work for custom CListCtl class无法让 OnContextMenu 为自定义 CListCtl 类工作
【发布时间】:2010-02-05 13:49:16
【问题描述】:

我正在尝试使上下文菜单适用于 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");
}

【问题讨论】:

    标签: mfc contextmenu clistctrl


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      相关资源
      最近更新 更多