NM_RDBLCLK not working for CTreeCtrl
-
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 hereMessageBox(\_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 ?
Perhaps because some of other handlers such as (
OnRButtonUp, OnContextMenu
) intercept it?
-
Perhaps because some of other handlers such as (
OnRButtonUp, OnContextMenu
) intercept it?
These handlers were not mapped in message map, but, just to be sure, I have commented them:
// 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()// CTestTreeView
IMPLEMENT_DYNCREATE(CTestTreeView, CFormView)
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 hereMessageBox(\_T("Aha")); \*pResult = 0;
}
Still not working NM_RDBLCLK handler at all ! Strange ...
-
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 hereMessageBox(\_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 ?
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. -
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. -
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 ?
From your initial post:
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
That is an MFC handler for
WM_CONTEXTMENU
. -
From your initial post:
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
That is an MFC handler for
WM_CONTEXTMENU
. -
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.
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) MFCCWnd
or derivatives handlers. Another source of not getting the notification might be handling the message in your derived tree control usingON_NOTIFY_REFLECT()
. If so, useON_NOTIFY_REFLECT_EX()
instead and returnFALSE
to get the notification passed to the parent. -
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) MFCCWnd
or derivatives handlers. Another source of not getting the notification might be handling the message in your derived tree control usingON_NOTIFY_REFLECT()
. If so, useON_NOTIFY_REFLECT_EX()
instead and returnFALSE
to get the notification passed to the parent. -
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 hereMessageBox(\_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 ?
Be sure that your CTreeCtrl has the CS_DBLCLKS class style. Try to handle WM_RBUTTONDBLCLK message.
-
Be sure that your CTreeCtrl has the CS_DBLCLKS class style. Try to handle WM_RBUTTONDBLCLK message.
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 hereMessageBox(\_T("Right dbl-click")); \*pResult = 0;
}
void CTestTreeView::OnNMDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code hereMessageBox(\_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.
-
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 hereMessageBox(\_T("Right dbl-click")); \*pResult = 0;
}
void CTestTreeView::OnNMDblclkTree1(NMHDR *pNMHDR, LRESULT *pResult)
{
// TODO: Add your control notification handler code hereMessageBox(\_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.
_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.
-
_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.
-
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 !
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.