Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - CXTTreeCtrl Context Menu
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

CXTTreeCtrl Context Menu

 Post Reply Post Reply
Author
Message
webjeff View Drop Down
Newbie
Newbie


Joined: 04 November 2006
Location: United States
Status: Offline
Points: 5
Post Options Post Options   Thanks (0) Thanks(0)   Quote webjeff Quote  Post ReplyReply Direct Link To This Post Topic: CXTTreeCtrl Context Menu
    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

Back to Top
kstowell View Drop Down
Admin Group
Admin Group


Joined: 25 January 2003
Location: MIchigan, USA
Status: Offline
Points: 496
Post Options Post Options   Thanks (0) Thanks(0)   Quote kstowell Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Kukis View Drop Down
Newbie
Newbie


Joined: 24 May 2006
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote Kukis Quote  Post ReplyReply Direct Link To This Post Posted: 26 February 2007 at 11:18am
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.