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
questiondata-structureshelp
6 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

    Hi all, i have a tree control in which i want to show the popup menu when someone right clicks on item. so that i hadled the NM_RCLICK message but the pop up menu comes somewhere near start button!! the code is as follows void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult) { NM_TREEVIEW* pNmTreeVew = NULL; pNmTreeVew =(NM_TREEVIEW*) pNMHDR; if(pNmTreeVew) { CPoint point; point.x = pNmTreeVew->ptDrag.x; point.y = pNmTreeVew->ptDrag.y;/* HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1)); if(hMenu) { TrackPopupMenu(hMenu,0,point.x,point.y,0,pTreeCtrl->m_hWnd,NULL); } } } What can be the problem with this code? actually when i debugged the code it point.y shows some big value so please tell what is the problem Thanks and regards Harshal

    M V 2 Replies Last reply
    0
    • H harsha_1234

      Hi all, i have a tree control in which i want to show the popup menu when someone right clicks on item. so that i hadled the NM_RCLICK message but the pop up menu comes somewhere near start button!! the code is as follows void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult) { NM_TREEVIEW* pNmTreeVew = NULL; pNmTreeVew =(NM_TREEVIEW*) pNMHDR; if(pNmTreeVew) { CPoint point; point.x = pNmTreeVew->ptDrag.x; point.y = pNmTreeVew->ptDrag.y;/* HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1)); if(hMenu) { TrackPopupMenu(hMenu,0,point.x,point.y,0,pTreeCtrl->m_hWnd,NULL); } } } What can be the problem with this code? actually when i debugged the code it point.y shows some big value so please tell what is the problem Thanks and regards Harshal

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

      Hi, it retrieves you coordinates for the screen and you need convert it to client. Use ScreenToClient method of treectrl: void ScreenToClient( LPPOINT lpPoint ) const;

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

      H 1 Reply Last reply
      0
      • M Mila025

        Hi, it retrieves you coordinates for the screen and you need convert it to client. Use ScreenToClient method of treectrl: void ScreenToClient( LPPOINT lpPoint ) const;

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

        H Offline
        H Offline
        harsha_1234
        wrote on last edited by
        #3

        I have done it this way but still it shows the menu at same position.

        M 1 Reply Last reply
        0
        • H harsha_1234

          Hi all, i have a tree control in which i want to show the popup menu when someone right clicks on item. so that i hadled the NM_RCLICK message but the pop up menu comes somewhere near start button!! the code is as follows void CTreeViewDlg::OnNMRclickTree1(NMHDR *pNMHDR, LRESULT *pResult) { NM_TREEVIEW* pNmTreeVew = NULL; pNmTreeVew =(NM_TREEVIEW*) pNMHDR; if(pNmTreeVew) { CPoint point; point.x = pNmTreeVew->ptDrag.x; point.y = pNmTreeVew->ptDrag.y;/* HMENU hMenu = LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1)); if(hMenu) { TrackPopupMenu(hMenu,0,point.x,point.y,0,pTreeCtrl->m_hWnd,NULL); } } } What can be the problem with this code? actually when i debugged the code it point.y shows some big value so please tell what is the problem Thanks and regards Harshal

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

          I think the pNMHDR argument of your handler actually does not point to NMTREEVIEW structure. (See the documentation of NM_RCLICK in case of tree controls). But you can obtain the current cursor position using GetCursorPos function:

          CPoint point;
          GetCursorPosition(&point);
          

          I hope this helps.

          1 Reply Last reply
          0
          • H harsha_1234

            I have done it this way but still it shows the menu at same position.

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

            Try GetMessagePos(): ... point = (CPoint) GetMessagePos(); tree->ScreenToClient(&point); In my case works fine.

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

            H 1 Reply Last reply
            0
            • M Mila025

              Try GetMessagePos(): ... point = (CPoint) GetMessagePos(); tree->ScreenToClient(&point); In my case works fine.

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

              H Offline
              H Offline
              harsha_1234
              wrote on last edited by
              #6

              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; } i have done something like this Noe the pop up menu is poping up but whenever i click on something it does not go to respective handler!! Thanks and regards Harshal

              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