Question

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");
}
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top