使用MFC Ribbon的框架,在OutLookBar上点击鼠标右键,往往弹出一个系统默认的菜单,如下图:我尝试了多种方法都不能将其禁止。
经过跟踪调试,当按下鼠标右键时,首先响应的Windows消息是WM_CONTEXTMENU,而不是WM_RBUTTONDOWN。
可以在创建OutlookBar的地方设置断点,单步跟踪进入MFC代码。
这样的目的是,VisualStudio帮我们打开CPP文件(否则记不住.h对应的.cpp),进入了afxdockablepane.cpp文件,在
- void CDockablePane::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- if (IsTracked())
- {
- return;
- }
-
- if (m_bCaptionButtonsCaptured)
- {
- StopCaptionButtonsTracking();
- }
-
- CPane::OnContextMenu(pWnd, point);
- }
继续跟踪到达:
- void CPane::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
- {
- if (CMFCPopupMenu::GetActiveMenu() != NULL)
- {
- return;
- }
-
- if (!CMFCToolBar::IsCustomizeMode())
- {
- if (OnShowControlBarMenu(point))
- {
- return;
- }
-
- CFrameWnd* pParentFrame = DYNAMIC_DOWNCAST(CFrameWnd, m_pDockSite);
- if (pParentFrame == NULL)
- {
- pParentFrame = AFXGetTopLevelFrame(this);
- }
-
- if (pParentFrame != NULL)
- {
- ASSERT_VALID(pParentFrame);
-
- OnPaneContextMenu(pParentFrame, point);
- }
- }
- }
如果将CMFCToolBar::IsCustomizeModel()置为TRUE,则不再弹出菜单,因此在创建OutlookBar后,立刻将该标志 置为TRUE。如下:
- DWORD style = WS_CHILD | WS_VISIBLE | CBRS_LEFT/* | CBRS_ALIGN_ANY*/;
- if (!m_wndOutlookBar.Create(strTemp, this, CRect(0, 0, 250, 20000), 0, style))
- {
- return FALSE; // fail to create
- }
-
- //禁止系统默认的弹出菜单
- CMFCToolBar::SetCustomizeMode(TRUE);
至此,不再弹出ContexMenu
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。