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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CTreeCtrl right mouse click handling :(

CTreeCtrl right mouse click handling :(

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structures
6 Posts 2 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I've faced with some odd problem in my code. I have CTreeView in my app and want to display popup menu when I'd made right mouse click at some tree element. In my NM_RCLICK handler I cast pNMHDR to pointer to NMTREEVIEW structure as usuall I had done with CListCtrl - NMLISTVIEW. But after all of that when I tried to use values in ptDrag member I've get garbage only. Thanks for any help:confused:

    L 2 Replies Last reply
    0
    • L Lost User

      I've faced with some odd problem in my code. I have CTreeView in my app and want to display popup menu when I'd made right mouse click at some tree element. In my NM_RCLICK handler I cast pNMHDR to pointer to NMTREEVIEW structure as usuall I had done with CListCtrl - NMLISTVIEW. But after all of that when I tried to use values in ptDrag member I've get garbage only. Thanks for any help:confused:

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      afx_msg void OnRclickTree1(NMHDR* pNMHDR, LRESULT* pResult); ON_NOTIFY(NM_RCLICK, ID_XML_TREE, OnRclickTree1) void C3DTabViewBar::OnRclickTree1(NMHDR* pNMHDR, LRESULT* pResult) { UNREFERENCED_PARAMETER(pNMHDR); // TODO: Add your control notification handler code here TRACE(_T("OnRclickTree1\n")); HTREEITEM hItem = m_treeClass.GetSelectedItem(); if (hItem != NULL) { CCMGTreeData* pData = reinterpret_cast(m_treeClass.GetItemData(hItem)); switch (pData->GetType()) { case CCMGTreeData::REFERENCES: DoPopupMenu(IDR_REFERENCES); break; case CCMGTreeData::SCHEMAS: DoPopupMenu(IDR_SCHEMAS); break; } } *pResult = 0; } void C3DTabViewBar::DoPopupMenu(UINT nMenuID) { CMenu popMenu; popMenu.LoadMenu(nMenuID); CPoint posMouse; GetCursorPos(&posMouse); UINT uiDisable = MF_BYCOMMAND|MF_GRAYED; UINT uiEnable = MF_BYCOMMAND|MF_ENABLED; if (nMenuID == IDR_REFERENCES) { popMenu.EnableMenuItem(ID_REFERENCES_ADD_MESSAGE_DEFENITION, IsRefernceIncluded(CCMGTreeData::MESSAGE_DEFENITION) ? uiDisable: uiEnable); popMenu.EnableMenuItem(ID_REFERENCES_ADD_CLASS_OF_SERVICE, IsRefernceIncluded(CCMGTreeData::CLASS_OF_SERVICE) ? uiDisable: uiEnable); popMenu.EnableMenuItem(ID_REFERENCES_ADD_BALANCE_DEFENITION, IsRefernceIncluded(CCMGTreeData::BALANCE_DEFENITION) ? uiDisable: uiEnable); } popMenu.GetSubMenu(0)->TrackPopupMenu(0, posMouse.x, posMouse.y, this); } Good luck! :)

      1 Reply Last reply
      0
      • L Lost User

        I've faced with some odd problem in my code. I have CTreeView in my app and want to display popup menu when I'd made right mouse click at some tree element. In my NM_RCLICK handler I cast pNMHDR to pointer to NMTREEVIEW structure as usuall I had done with CListCtrl - NMLISTVIEW. But after all of that when I tried to use values in ptDrag member I've get garbage only. Thanks for any help:confused:

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Please look DAOVIEW example from MS VisualC++.

        M 1 Reply Last reply
        0
        • L Lost User

          Please look DAOVIEW example from MS VisualC++.

          M Offline
          M Offline
          Morozov Alexey
          wrote on last edited by
          #4

          Thanks a lot. It really gave me a good idea. But look at this code: void CLeftView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) { unsigned char *p = (unsigned char*) pNMHDR; p -= 4; // !!!!!!!!!!!!! NMTREEVIEW *z = (NMTREEVIEW*) p; CPoint ptXY = z->ptDrag; } It works too!!! ptXY after all of these manipulations is a real mouse coordinates X|

          L 2 Replies Last reply
          0
          • M Morozov Alexey

            Thanks a lot. It really gave me a good idea. But look at this code: void CLeftView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) { unsigned char *p = (unsigned char*) pNMHDR; p -= 4; // !!!!!!!!!!!!! NMTREEVIEW *z = (NMTREEVIEW*) p; CPoint ptXY = z->ptDrag; } It works too!!! ptXY after all of these manipulations is a real mouse coordinates X|

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Trust me, your code is very bad idea for support etc, etc. Regrds, Sergey

            1 Reply Last reply
            0
            • M Morozov Alexey

              Thanks a lot. It really gave me a good idea. But look at this code: void CLeftView::OnRclick(NMHDR* pNMHDR, LRESULT* pResult) { unsigned char *p = (unsigned char*) pNMHDR; p -= 4; // !!!!!!!!!!!!! NMTREEVIEW *z = (NMTREEVIEW*) p; CPoint ptXY = z->ptDrag; } It works too!!! ptXY after all of these manipulations is a real mouse coordinates X|

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              http://www.mvps.org/vcfaq/mfc/6.htm /* Get the mouse cursor position */ DWORD dwPos = GetMessagePos(); More simple and portable. ;)

              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