愛悠閑 > MFC 動態創建右鍵菜單

MFC 動態創建右鍵菜單

標簽: mfc,command  |  作者: jtl996 相關  |  發布日期 : 2015-04-24  |  熱度 : 150°
 
-------------------------------------------------》創建右鍵菜單

CMenu menu;
menu.CreatePopupMenu();
menu.AppendMenu(MF_SEPARATOR);
menu.AppendMenu(0,ID_POPUP_MEMUREN1,"新建聯系人");

int nIndex = m_list.GetSelectionMark();
if(nIndex==-1)
{
  menu.AppendMenu(1,ID_POPUP_MEMUREN2,"編輯聯系人");
  menu.AppendMenu(1,ID_POPUP_MEMUREN3,"刪除聯系人");
}
else
{
  menu.AppendMenu(0,ID_POPUP_MEMUREN2,"編輯聯系人");
  menu.AppendMenu(0,ID_POPUP_MEMUREN3,"刪除聯系人");
}
menu.CheckMenuRadioItem(ID_POPUP_MEMUREN1,ID_POPUP_MEMUREN2,ID_POPUP_MEMUREN3,MF_BYCOMMAND);
::GetCursorPos(&point);
menu.TrackPopupMenu(TPM_RIGHTBUTTON,point.x,point.y,this);
menu.DestroyMenu();
return;

----------------------------------------------------------------------------------------》消息映射

ON_COMMAND_RANGE(ID_POPUP_MEMUREN1,ID_POPUP_MEMUREN3,OperateRen)

-------------------------------------------------------------------》消息響應

void CLianXiRen::OperateRen(UINT uID)
{
switch(uID)
{
case ID_POPUP_MEMUREN1:   //添加
  ADDRen();
  break;
case ID_POPUP_MEMUREN2:   //編輯
  EditRen();
  break;
case ID_POPUP_MEMUREN3:    //刪除
  DelRen();
  break;
}
}


快乐彩中奖说明