void CMFC_PEDlg::OnRclickTreePeheader(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CRect rect;
CPoint point;
GetCursorPos(&point);
m_TreeCtrl.ScreenToClient(&point);
HTREEITEM hSelItem = m_TreeCtrl.HitTest(point, NULL);
CString csItemName = m_TreeCtrl.GetItemText(hSelItem);
if(hSelItem)
{
// 可以在此过滤点击树叶或树枝才弹出菜单,我没有限制
m_TreeCtrl.SelectItem(hSelItem);
m_TreeCtrl.ClientToScreen(&point);
// 创建自定义菜单
CMenu menu;
VERIFY(menu.LoadMenu(IDR_MENU1));
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;
}
树形控件右键菜单
最新推荐文章于 2024-06-24 17:39:01 发布