
CTreeCtrl is not doing the business
I've done the same thing in the following way, and it works fine:
void CAlsTreeDlg::OnRclickAlstree(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
// TODO: Add your control notification handler code here
UINT nFlags;
CPoint curPoint;
HTREEITEM rightButtonItemP;
GetCursorPos (&curPoint);
// alsTree is a member varibale of the class containing a pointer to
// the tree control
alsTree->ScreenToClient (&curPoint);
rightButtonItemP = alsTree->HitTest (curPoint, &nFlags);
if (rightButtonItemP != NULL)
{
RECT itemRect;
if (alsTree->GetItemRect (rightButtonItemP, &itemRect, TRUE))
{
CMenu treePopup;
alsTree->ClientToScreen (&itemRect);
treePopup.LoadMenu (IDR_TREEPOPUP);
treePopup.GetSubMenu(0)->TrackPopupMenu (TPM_LEFTALIGN,
itemRect.right, itemRect.top, this);
treePopup.DestroyMenu ();
}
}
Quote:
}
The problem is, that the selection changes AFTER processing the right mouse
click.
I've found this suggestion somewhere in the online help.
Hope this helps.
--
Dirk Bohnemeyer
p.s. For e-mail remove one of the 'o's from my address.
-------------------------------------------------------
Quote:
>All,
>I'm using a tree control stuck in a CDialogBar docked to the edge of my
>frame window, and I'm intercepting two notifications: TVN_SELCHANGE and
>NM_RCLICK. My problem is as follows:
>Upon intercepting the NM_RCLICK notification, which I intend to use to
>display a popup context menu for individual tree items, I find that the
>control's perception of the selected item has not changed, even though the
>selection has changed on screen. Thus, when I attempt to retrieve the item
>rectangle so that I can display the menu at the right position, I get the
>previous item, not the new one (and don't even ask me how {*filter*}
GetItemRect()
>seems to be). My questions are therefore:
>1. How do I get a right click selection change to register a TVN_SELCHANGE
>BEFORE a NM_RCLICK comes in?
>2. Does CTreeCtrl->GetItemRect() work properly (it seems to always return a
>rect.left of 0)?
>3. Are there better ways of doing this?