CTreeCtrl 右键选中节点并显示菜单

来源:互联网 发布:京东金融数据分析 编辑:程序博客网 时间:2024/04/29 13:47

void C***Dlg::OnRclickTreeKey(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here

// 选中当前右键点击的节点
POINT pos ;
if(!GetCursorPos(&pos))
   return ;
m_KeyList.ScreenToClient(&pos);

UINT uFlags;
HTREEITEM hItem = m_KeyList.HitTest(pos, &uFlags);
if ((hItem != NULL) && (TVHT_ONITEM & uFlags))
{
   m_KeyList.Select(hItem, TVGN_CARET);
}

// 显示菜单
CRect rect ;
this->GetClientRect(&rect) ;
ClientToScreen(&rect) ;
m_KeyList.ClientToScreen(&pos);

int iCode= rect.PtInRect(pos) ;

CMenu m_Menu,*p_Menu=NULL ;
if(iCode)
{
   m_Menu.LoadMenu( IDR_MENU_REG) ;
   p_Menu = (CMenu*) m_Menu.GetSubMenu(0);
   if( p_Menu != NULL)
    p_Menu->TrackPopupMenu( TPM_RIGHTBUTTON|TPM_LEFTALIGN, pos.x, pos.y, this);
   p_Menu = NULL;
   //mouse_event(MOUSEEVENTF_RIGHTUP, pos.x, pos.y, 0, NULL);
}

// AfxMessageBox(m_szMsg);
*pResult = 0;
}

原创粉丝点击