1》新建菜单栏。
2》重载virtual BOOL PreTranslateMessage(MSG* pMsg);
3》加载菜单栏。
4》设置菜单栏显示位置。
5》右键显示菜单栏。
6》分离菜单栏。
7》m_ALarmMsgListBox为CListBox绑定变量。
BOOL CMFCApplicationJstReflowDlg::PreTranslateMessage(MSG* pMsg)
{
CWnd* m_tHwnd = AfxGetApp()->GetMainWnd();
if (WM_RBUTTONDOWN == pMsg->message)
{
CPoint pt;
CRect rtClient;
m_ALarmMsgListBox.GetClientRect(&rtClient);
m_ALarmMsgListBox.ClientToScreen(&rtClient);
int isCrollPos = m_ALarmMsgListBox.GetScrollPos(SB_VERT);
GetCursorPos(&pt);
int iSelect = (pt.y - rtClient.top + isCrollPos * m_ALarmMsgListBox.GetItemHeight(0)) / m_ALarmMsgListBox.GetItemHeight(0);
m_ALarmMsgListBox.SetCurSel(iSelect);
m_ALarmMsgListBox.Invalidate();
m_ALarmMsgListBox.RedrawWindow();
if (rtClient.PtInRect(pt) && iSelect < m_ALarmMsgListBox.GetCount())
{
CMenu m_Mymenu;
m_Mymenu.LoadMenuW(IDR_MENUCLIST);
m_Mymenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this, NULL);
m_Mymenu.Detach();
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}