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. NM_RDBLCLK not working for CTreeCtrl

NM_RDBLCLK not working for CTreeCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
14 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.
  • _ _Flaviu

    I have made an test app, SDI, MFC, with view based on CFormView. On this CView, I have put an CTreeCtrl object. And I have mapped NM_RDBLCLK, in this way:

    // header
    // Generated message map functions
    protected:
    afx_msg void OnFilePrintPreview();
    afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
    afx_msg void OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult);
    DECLARE_MESSAGE_MAP()

    and

    BEGIN_MESSAGE_MAP(CTestTreeView, CFormView)
    ON_NOTIFY(NM_RDBLCLK, IDC_TREE1, &CTestTreeView::OnNMRDblclkTree1)
    END_MESSAGE_MAP()

    ....
    ....
    void CTestTreeView::OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
    {
    // TODO: Add your control notification handler code here

    MessageBox(\_T("Aha"));
    
    \*pResult = 0;
    

    }

    but I hit right-double-click, is happen nothing ... why ? I haven't done enough to have this feature on my CTreeCtrl object ?

    J Offline
    J Offline
    Jochen Arndt
    wrote on last edited by
    #4

    Not a solution but some thoughts. Your parent view has a context menu handler. As a result that will be always called before the NM_RDBLCLK handler when the tree control does not handle it:

    WM_CONTEXTMENU message (Windows)[^]:

    If a window does not display a shortcut menu it should pass this message to the DefWindowProc function. If a window is a child window, DefWindowProc sends the message to the parent. Otherwise, DefWindowProc displays a default shortcut menu if the specified position is in the window's caption.

    If you have a context menu (in the parent and/or child) it will be shown before the NM_RDBLCLK handler is called. Then there should be no reason to act upon double clicks too. The message will even not being generated when the mouse is over the meanwhile opened popup menu when the second click occurs.

    _ 1 Reply Last reply
    0
    • J Jochen Arndt

      Not a solution but some thoughts. Your parent view has a context menu handler. As a result that will be always called before the NM_RDBLCLK handler when the tree control does not handle it:

      WM_CONTEXTMENU message (Windows)[^]:

      If a window does not display a shortcut menu it should pass this message to the DefWindowProc function. If a window is a child window, DefWindowProc sends the message to the parent. Otherwise, DefWindowProc displays a default shortcut menu if the specified position is in the window's caption.

      If you have a context menu (in the parent and/or child) it will be shown before the NM_RDBLCLK handler is called. Then there should be no reason to act upon double clicks too. The message will even not being generated when the mouse is over the meanwhile opened popup menu when the second click occurs.

      _ Offline
      _ Offline
      _Flaviu
      wrote on last edited by
      #5

      Yes, I see your point, but I don't have any right click, or contextMenu, or shortcut menu handler neither in CMyView (derived from CFormView), neither in my CTreeCtrl object (IDC_TREE1) ... or, I miss something ?

      J 1 Reply Last reply
      0
      • _ _Flaviu

        Yes, I see your point, but I don't have any right click, or contextMenu, or shortcut menu handler neither in CMyView (derived from CFormView), neither in my CTreeCtrl object (IDC_TREE1) ... or, I miss something ?

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #6

        From your initial post:

        afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);

        That is an MFC handler for WM_CONTEXTMENU.

        _ 1 Reply Last reply
        0
        • J Jochen Arndt

          From your initial post:

          afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);

          That is an MFC handler for WM_CONTEXTMENU.

          _ Offline
          _ Offline
          _Flaviu
          wrote on last edited by
          #7

          Yes, that was the default code put there by MFC wizard, but there was not mapped in the message map ... anyway, I have commented up, and that was change nothing.

          J 1 Reply Last reply
          0
          • _ _Flaviu

            Yes, that was the default code put there by MFC wizard, but there was not mapped in the message map ... anyway, I have commented up, and that was change nothing.

            J Offline
            J Offline
            Jochen Arndt
            wrote on last edited by
            #8

            It is sufficient to comment the message map entries (which should be created too by the wizard). By the presence of the context menu handler I assumed that you want to use it. All I can think of is that the NM_RDBLCLK notification is not send by some processing in the default (right mouse button related) MFC CWnd or derivatives handlers. Another source of not getting the notification might be handling the message in your derived tree control using ON_NOTIFY_REFLECT(). If so, use ON_NOTIFY_REFLECT_EX() instead and return FALSE to get the notification passed to the parent.

            _ 1 Reply Last reply
            0
            • J Jochen Arndt

              It is sufficient to comment the message map entries (which should be created too by the wizard). By the presence of the context menu handler I assumed that you want to use it. All I can think of is that the NM_RDBLCLK notification is not send by some processing in the default (right mouse button related) MFC CWnd or derivatives handlers. Another source of not getting the notification might be handling the message in your derived tree control using ON_NOTIFY_REFLECT(). If so, use ON_NOTIFY_REFLECT_EX() instead and return FALSE to get the notification passed to the parent.

              _ Offline
              _ Offline
              _Flaviu
              wrote on last edited by
              #9

              Thank you for your time, Jochen. No, I am not using any derived CTreeCtrl, so, I cannot use anything than ON_NOTIFY notification.

              1 Reply Last reply
              0
              • _ _Flaviu

                I have made an test app, SDI, MFC, with view based on CFormView. On this CView, I have put an CTreeCtrl object. And I have mapped NM_RDBLCLK, in this way:

                // header
                // Generated message map functions
                protected:
                afx_msg void OnFilePrintPreview();
                afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
                afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
                afx_msg void OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult);
                DECLARE_MESSAGE_MAP()

                and

                BEGIN_MESSAGE_MAP(CTestTreeView, CFormView)
                ON_NOTIFY(NM_RDBLCLK, IDC_TREE1, &CTestTreeView::OnNMRDblclkTree1)
                END_MESSAGE_MAP()

                ....
                ....
                void CTestTreeView::OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
                {
                // TODO: Add your control notification handler code here

                MessageBox(\_T("Aha"));
                
                \*pResult = 0;
                

                }

                but I hit right-double-click, is happen nothing ... why ? I haven't done enough to have this feature on my CTreeCtrl object ?

                V Offline
                V Offline
                Victor Nijegorodov
                wrote on last edited by
                #10

                Be sure that your CTreeCtrl has the CS_DBLCLKS class style. Try to handle WM_RBUTTONDBLCLK message.

                _ 1 Reply Last reply
                0
                • V Victor Nijegorodov

                  Be sure that your CTreeCtrl has the CS_DBLCLKS class style. Try to handle WM_RBUTTONDBLCLK message.

                  _ Offline
                  _ Offline
                  _Flaviu
                  wrote on last edited by
                  #11

                  I have tried double-click too, not working:

                  ON\_NOTIFY(NM\_RDBLCLK, IDC\_TREE1, &CTestTreeView::OnNMRDblclkTree1)
                  ON\_NOTIFY(NM\_DBLCLK, IDC\_TREE1, &CTestTreeView::OnNMDblclkTree1)
                  

                  void CTestTreeView::OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
                  {
                  // TODO: Add your control notification handler code here

                  MessageBox(\_T("Right dbl-click"));
                  
                  \*pResult = 0;
                  

                  }

                  void CTestTreeView::OnNMDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
                  {
                  // TODO: Add your control notification handler code here

                  MessageBox(\_T("Left dbl-click"));
                  
                  \*pResult = 0;
                  

                  }

                  I modified the control style, as follow:

                  void CTestTreeView::OnInitialUpdate()
                  {
                  CFormView::OnInitialUpdate();
                  GetParentFrame()->RecalcLayout();

                  m\_Tree.ModifyStyle(0, CS\_DBLCLKS);
                  
                  ResizeParentToFit();
                  

                  }

                  where m_Tree is my CTreeCtrl object.

                  V 1 Reply Last reply
                  0
                  • _ _Flaviu

                    I have tried double-click too, not working:

                    ON\_NOTIFY(NM\_RDBLCLK, IDC\_TREE1, &CTestTreeView::OnNMRDblclkTree1)
                    ON\_NOTIFY(NM\_DBLCLK, IDC\_TREE1, &CTestTreeView::OnNMDblclkTree1)
                    

                    void CTestTreeView::OnNMRDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
                    {
                    // TODO: Add your control notification handler code here

                    MessageBox(\_T("Right dbl-click"));
                    
                    \*pResult = 0;
                    

                    }

                    void CTestTreeView::OnNMDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
                    {
                    // TODO: Add your control notification handler code here

                    MessageBox(\_T("Left dbl-click"));
                    
                    \*pResult = 0;
                    

                    }

                    I modified the control style, as follow:

                    void CTestTreeView::OnInitialUpdate()
                    {
                    CFormView::OnInitialUpdate();
                    GetParentFrame()->RecalcLayout();

                    m\_Tree.ModifyStyle(0, CS\_DBLCLKS);
                    
                    ResizeParentToFit();
                    

                    }

                    where m_Tree is my CTreeCtrl object.

                    V Offline
                    V Offline
                    Victor Nijegorodov
                    wrote on last edited by
                    #12

                    _Flaviu wrote:

                    m_Tree.ModifyStyle(0, CS_DBLCLKS);

                    No, it won't work! just because CS_DBLCLKS is not a window style. It is a window class style! But forget this! Note that double-click in a tree control is used by default to expand/collapse tree items! So these messages are handled by control itself and therefore you cannot handle them in your code.

                    _ 1 Reply Last reply
                    0
                    • V Victor Nijegorodov

                      _Flaviu wrote:

                      m_Tree.ModifyStyle(0, CS_DBLCLKS);

                      No, it won't work! just because CS_DBLCLKS is not a window style. It is a window class style! But forget this! Note that double-click in a tree control is used by default to expand/collapse tree items! So these messages are handled by control itself and therefore you cannot handle them in your code.

                      _ Offline
                      _ Offline
                      _Flaviu
                      wrote on last edited by
                      #13

                      Yes, you are right, I guess this messages (double-click, and right double click) are handled by the control, that is why I cannot catch them. Thank you !

                      V 1 Reply Last reply
                      0
                      • _ _Flaviu

                        Yes, you are right, I guess this messages (double-click, and right double click) are handled by the control, that is why I cannot catch them. Thank you !

                        V Offline
                        V Offline
                        Victor Nijegorodov
                        wrote on last edited by
                        #14

                        You could subclass the Tree Control (in your own class derived from CTreeCtrl). In the derived class implement the ON_NOTIFY_REFLECT_EX macro to handle left/right double click and then pass (or not) this message for the further handling.

                        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