Print Page | Close Window

CXTTreeCtrl Context Menu

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=6503
Printed Date: 12 November 2025 at 9:46am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: CXTTreeCtrl Context Menu
Posted By: webjeff
Subject: CXTTreeCtrl Context Menu
Date Posted: 25 February 2007 at 5:16pm
I have a CXTTreeCtrl where I want to right click on a node and have functions listed on that node.

I added a function on the command "WM_CONTEXTMENU" and that works, except you need to double right-click.  I can't seem to figure out why that is, nor do I see any other ways to bring up the context menu.

Any ideas why WM_CONTEXTMENU requires a double right click?

Thanks

Jeff




Replies:
Posted By: kstowell
Date Posted: 25 February 2007 at 11:19pm
Hello,
 
Sounds like you may be using a CXTTreeView? If so there is a bug in MFC that prevents WM_CONTEXTMENU from getting fired correctly for a CTreeView or CListView derived class.
 
Even if you are not using a CTreeView you should be able to use the following code as a work around, add a WM_RBUTTONDOWN handler in place of your WM_CONTEXTMENU handler, for example:
 
BEGIN_MESSAGE_MAP(CTestAppView, CTreeView)
    //{{AFX_MSG_MAP(CTestAppView)
    ON_WM_RBUTTONDOWN()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CTestAppView::OnRButtonDown(UINT nFlags, CPoint point)
{
    CPoint pt = point;
    ClientToScreen(&pt);
   
    if (pt.x == -1 && pt.y == -1)
    {
        // keystroke invocation
        CRect rect;
        GetClientRect(rect);
        ClientToScreen(rect);
       
        pt = rect.TopLeft();
        pt.Offset(5, 5);
    }
   
    CMenu menu;
    VERIFY(menu.LoadMenu(CG_IDR_POPUP_TEST_APP_VIEW));
   
    CMenu* pPopup = menu.GetSubMenu(0);
    ASSERT(pPopup != NULL);
    CWnd* pWndPopupOwner = this;
   
    while (pWndPopupOwner->GetStyle() & WS_CHILD)
        pWndPopupOwner = pWndPopupOwner->GetParent();
   
    pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y,
        pWndPopupOwner);
   
    CTreeView::OnRButtonDown(nFlags, point);
}
 
Hope this helps.
 
Regards,
Kirk Stowell
Codejock Software


Posted By: Kukis
Date Posted: 26 February 2007 at 11:18am

Or check MSDN here:

http://support.microsoft.com/kb/222905 - http://support.microsoft.com/kb/222905



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net