|
|
|
|
Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
Adrian M
|
Mar 1, 2005 - 7:04 PM
|
I have a tree control inside a CExtControlBar. Although I have defined the handler for the OnContextMenu for the tree control, this method is notified only on a right button double click, not on single click. I can receive the OnNMRclick notification though. Any solution to this? Thanks, Adrian
|
|
Technical Support
|
Mar 2, 2005 - 1:54 AM
|
We suggest you to declare a CTreeCtrl -derived class and implement the NM_RCLICK and WM_CONTEXTMENU handlers in it like as follows:HTREEITEM m_hCurrentItem; // CMyTree member variable
void CMyTree::OnRclick(NMHDR* pNMHDR, LRESULT* pResult)
{
UINT nFlags;
CPoint curPoint;
GetCursorPos(&curPoint);
ScreenToClient(&curPoint);
HTREEITEM hCurrentItem = HitTest(curPoint, &nFlags);
if(hCurrentItem != NULL)
{
if( SelectItem(hCurrentItem) )
m_hCurrentItem = hCurrentItem;
// Send WM_CONTEXTMENU to self
SendMessage(WM_CONTEXTMENU,
(WPARAM) m_hWnd, GetMessagePos());
}
*pResult = 1;
}
void CMyTree::OnContextMenu(CWnd* pWnd, CPoint point)
{
if( !m_hCurrentItem )
return;
CPoint posMouse, menuCoord;
VERIFY( GetCursorPos(&posMouse) );
ScreenToClient(&posMouse);
UINT uFlags;
HTREEITEM hItem = HitTest(posMouse, &uFlags);
if ( (hItem != NULL)
&& (TVHT_ONITEM & uFlags)
&& (hItem == m_hCurrentItem)
)
VERIFY( GetCursorPos(&menuCoord) );
else
{
RECT r;
if( !GetItemRect(m_hCurrentItem, &r, TRUE) )
return;
menuCoord = CPoint(r.left, r.bottom);
ClientToScreen(&menuCoord);
}
CExtPopupMenuWnd * pPopupWnd = new CExtPopupMenuWnd;
VERIFY(
pPopupWnd->LoadMenu(
m_hWnd,
IDR_POPUP_ON_TREE
)
);
VERIFY(
pPopupWnd->TrackPopupMenu(
TPMX_LEFTALIGN,
menuCoord.x,
menuCoord.y)
);
}
|
|
Adrian M
|
Mar 2, 2005 - 4:10 AM
|
Yes, this is what I did in my code too but I was wondering why the method OnContextMenu wasn’t called directly for single clicks, and I thought this had something to do with the control bar parent of the tree control. But this works too - thanks. Adrian
|
|
Technical Support
|
Mar 2, 2005 - 6:29 AM
|
The WM_CONTEXTMENU message is typically generated when the user uses SHIFT+F10 or the VK_APPS key (Applications key on the Natural keyboard).
|
|