1.定义菜单资源以及成员函数
CMenu menu;
OnInitDialog()函数加入:
menu.LoadMenu(IDR_TEXTMENU); //IDR_TEXTMENU为菜单的ID
2.PreTranslateMessage(MSG* pMsg)函数中加入:
if(pMsg->message==WM_RBUTTONUP && pMsg->hwnd==m_mytext.m_hWnd)
{
CMenu* pPopup =menu.GetSubMenu(0);
CRect rc;
CPoint point=pMsg->pt;
rc.top=point.x;
rc.left=point.y;
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,rc.top
,rc.left,this,&rc);
}
return CDialog::PreTranslateMessage(pMsg);