dkremer
asked on
Popup menu inside TreeView problem
Hi.
I want to create a popup menu on a right cick in a tree view.
The popup should be different if the click was on an item or not.
My problem is that the popup created upon clicking not on an item isn't
shown in the right place (next to mouse cursor) but a bit far from it.
My code follows :
void CLeftView::OnNMRclick(NMHD R *pNMHDR, LRESULT *pResult)
{
CMenu mPopups, *pFloatingPopup = NULL;
mPopups.LoadMenu(IDR_POPUP S);
CPoint pos;
GetCursorPos(&pos);
GetTreeCtrl().ScreenToClie nt(&pos);
UINT uFlags;
HTREEITEM hItem = GetTreeCtrl().HitTest(pos, &uFlags);
if (hItem != NULL && (uFlags & TVHT_ONITEM) != 0)
{
GetTreeCtrl().SelectItem(h Item);
pFloatingPopup = mPopups.GetSubMenu(0);
}
else // not on item
pFloatingPopup = mPopups.GetSubMenu(1);
pFloatingPopup->TrackPopup Menu(TPM_L EFTALIGN |TPM_RIGHTBUTTON, pos.x,
pos.y, AfxGetMainWnd());
*pResult = 0;
}
Any ideas as to why that happens and a fix ?
I want to create a popup menu on a right cick in a tree view.
The popup should be different if the click was on an item or not.
My problem is that the popup created upon clicking not on an item isn't
shown in the right place (next to mouse cursor) but a bit far from it.
My code follows :
void CLeftView::OnNMRclick(NMHD
{
CMenu mPopups, *pFloatingPopup = NULL;
mPopups.LoadMenu(IDR_POPUP
CPoint pos;
GetCursorPos(&pos);
GetTreeCtrl().ScreenToClie
UINT uFlags;
HTREEITEM hItem = GetTreeCtrl().HitTest(pos,
if (hItem != NULL && (uFlags & TVHT_ONITEM) != 0)
{
GetTreeCtrl().SelectItem(h
pFloatingPopup = mPopups.GetSubMenu(0);
}
else // not on item
pFloatingPopup = mPopups.GetSubMenu(1);
pFloatingPopup->TrackPopup
pos.y, AfxGetMainWnd());
*pResult = 0;
}
Any ideas as to why that happens and a fix ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Don't need to switch from screen to client since TrackPopupMenu takes screen coordinates.