Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CtreeCtrl Popupmenu

CtreeCtrl Popupmenu

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harsha_1234
    wrote on last edited by
    #1

    i am able to show the popup menu when user right clicks on tree view item but now the problem is that when user clicks on some Menuitem then the control doesn't reaches to the respective menu handler in fact nothing is getting called below is the code for showing the pop uo menu void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult) { CPoint ptMouse; DWORD dwPos; UINT nFlags; CTreeCtrl *pTreeCtrl; pTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREE1); { dwPos = ::GetMessagePos(); ptMouse.x = LOWORD (dwPos); ptMouse.y = HIWORD (dwPos); CPoint ptAction = ptMouse; // convert coordinates pTreeCtrl->ScreenToClient(&ptAction); // determine if click is on tree item HTREEITEM hItemRClick = pTreeCtrl->HitTest(ptAction, &nFlags); // if click is on tree item, if (hItemRClick != NULL) { // set selection to right+clicked item pTreeCtrl->SelectItem(hItemRClick); HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1)); if(hMenu) { hMenu = GetSubMenu(hMenu,1); if(hMenu) { TrackPopupMenu(hMenu,0,ptMouse.x,ptMouse.y,0,pTreeCtrl->m_hWnd,NULL); } } } } *pResult = 0; } Thanks and regards harshal

    M V 2 Replies Last reply
    0
    • H harsha_1234

      i am able to show the popup menu when user right clicks on tree view item but now the problem is that when user clicks on some Menuitem then the control doesn't reaches to the respective menu handler in fact nothing is getting called below is the code for showing the pop uo menu void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult) { CPoint ptMouse; DWORD dwPos; UINT nFlags; CTreeCtrl *pTreeCtrl; pTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREE1); { dwPos = ::GetMessagePos(); ptMouse.x = LOWORD (dwPos); ptMouse.y = HIWORD (dwPos); CPoint ptAction = ptMouse; // convert coordinates pTreeCtrl->ScreenToClient(&ptAction); // determine if click is on tree item HTREEITEM hItemRClick = pTreeCtrl->HitTest(ptAction, &nFlags); // if click is on tree item, if (hItemRClick != NULL) { // set selection to right+clicked item pTreeCtrl->SelectItem(hItemRClick); HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1)); if(hMenu) { hMenu = GetSubMenu(hMenu,1); if(hMenu) { TrackPopupMenu(hMenu,0,ptMouse.x,ptMouse.y,0,pTreeCtrl->m_hWnd,NULL); } } } } *pResult = 0; } Thanks and regards harshal

      M Offline
      M Offline
      Mila025
      wrote on last edited by
      #2

      hi again, and did you add ON_COMMAND handlers for each menu command ?

      ----------- Mila

      1 Reply Last reply
      0
      • H harsha_1234

        i am able to show the popup menu when user right clicks on tree view item but now the problem is that when user clicks on some Menuitem then the control doesn't reaches to the respective menu handler in fact nothing is getting called below is the code for showing the pop uo menu void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult) { CPoint ptMouse; DWORD dwPos; UINT nFlags; CTreeCtrl *pTreeCtrl; pTreeCtrl = (CTreeCtrl *)GetDlgItem(IDC_TREE1); { dwPos = ::GetMessagePos(); ptMouse.x = LOWORD (dwPos); ptMouse.y = HIWORD (dwPos); CPoint ptAction = ptMouse; // convert coordinates pTreeCtrl->ScreenToClient(&ptAction); // determine if click is on tree item HTREEITEM hItemRClick = pTreeCtrl->HitTest(ptAction, &nFlags); // if click is on tree item, if (hItemRClick != NULL) { // set selection to right+clicked item pTreeCtrl->SelectItem(hItemRClick); HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1)); if(hMenu) { hMenu = GetSubMenu(hMenu,1); if(hMenu) { TrackPopupMenu(hMenu,0,ptMouse.x,ptMouse.y,0,pTreeCtrl->m_hWnd,NULL); } } } } *pResult = 0; } Thanks and regards harshal

        V Offline
        V Offline
        Viorel
        wrote on last edited by
        #3

        I think instead of

        TrackPopupMenu(..., pTreeCtrl->m_hWnd, ...);
        

        you should try

        TrackPopupMenu(..., m_hWnd, ...);
        

        I hope this helps.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups