Popup menu in 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(NMHDR *pNMHDR, LRESULT *pResult) { CMenu mPopups, *pFloatingPopup = NULL; mPopups.LoadMenu(IDR_POPUPS); CPoint pos; GetCursorPos(&pos); GetTreeCtrl().ScreenToClient(&pos); UINT uFlags; HTREEITEM hItem = GetTreeCtrl().HitTest(pos, &uFlags); if (hItem != NULL && (uFlags & TVHT_ONITEM) != 0) { GetTreeCtrl().SelectItem(hItem); pFloatingPopup = mPopups.GetSubMenu(0); } else // not on item pFloatingPopup = mPopups.GetSubMenu(1); pFloatingPopup->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, pos.x, pos.y, AfxGetMainWnd()); *pResult = 0; } Any ideas as to why that happens and a fix ?