无法让 OnContextMenu 适用于自定义 CListCtl 类

发布于 2024-08-20 05:21:39 字数 831 浏览 3 评论 0原文

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

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");
}

I am trying to get a context menu to work for a CListCtrl derived class. I just created a method OnContextMenu, but it isn't being called. What am I missing? I am using Visual Studio 2008, to create a CDialog based MFC application.

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");
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

微凉 2024-08-27 05:21:39

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

I found out I had to add ON_WM_CONTEXTMENU() to message map.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文