怎么在鼠标右键 单击CTreeCtrl中的项的时候,弹出不同的菜单?
在一个对话框的程序里,放一个CTreeCtrl,
增加NM_RCLICK事件,在里面加了代码,弹出菜单,但那个菜单的定位有问题,总是偏得很厉害。
不知道是应该用ClientToScreen(&rect)还是用ScreenToClient(&rect)?
void CDialog_System_Configure::OnRclickTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
//先获取选择的点的Rect
HTREEITEM ht=this->m_Tree1.GetSelectedItem();
CString str;
//获取节点文字
sprintf(str,"[OnRclickTree1]%s",this->m_Tree1.GetItemText(ht));
AfxMessageBox(str);
CRect rect;
CPoint point;
//获取节点的位置
this->m_Tree1.GetItemRect(ht,&rect,false);
//转换有问题????
ClientToScreen(&rect);
point.x=rect.left;
point.y=rect.top;
//右键菜单
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_DIALOG__SYSTEM__CONFIGURE));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
*pResult = 0;
}