刚才做了个实验 在对话框上实现了该功能 看来我的弹出菜单被控件挡住了
- void CfdDlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- SHRGINFO shrgi = {0};
- shrgi.cbSize = sizeof(SHRGINFO);
- shrgi.hwndClient = m_hWnd;
- shrgi.ptDown.x = point.x;
- shrgi.ptDown.y = point.y;
- shrgi.dwFlags = SHRG_RETURNCMD;
- if(GN_CONTEXTMENU == ::SHRecognizeGesture(&shrgi))
- ContextMenu(point);
- else
- Default();
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CfdDlg::ContextMenu(CPoint point)
- {
- CMenu mnuCtxt;
- CMenu* pMenu;
- CWnd* pWnd;
- if(!IDM_MENU1)
- return;
- if(mnuCtxt.LoadMenu(IDM_MENU1))
- {
- pWnd = (/*m_pWndMenu ? m_pWndMenu : */AfxGetMainWnd());//就这个m_pWndMenu参数不知什么意思我直接用的AfxGetMainWnd()
- pMenu = mnuCtxt.GetSubMenu(0);
- if(pMenu)
- {
- ClientToScreen(&point);pMenu->TrackPopupMenu(TPM_LEFTALIGN,
- point.x, point.y, pWnd);
- }
- }
- }
The m_pWndMenu member variable holds a pointer to the command-processing window. This is useful if you want to show TAH context menus on controls placed in dialogs. In these situations you cannot use AfxGetMainWnd() because your menu commands might be either grayed, or worse, handled by another (hidden) window. So, m_pWndMenu will have the containing CDialog pointer.
这是codeproject上面对这个参数的解释,可惜小弟英文不行,没看懂.望各位大哥给予解释说明.