[英]MFC ribbon home button closes app with double click
I've faced with strange behaviour of a home ribbon button. 我遇到了首页功能区按钮的奇怪行为。
I've created standard MFC application in Visual Studio 2010 with Office template that has a ribbon control. 我已经在Visual Studio 2010中使用具有功能区控件的Office模板创建了标准的MFC应用程序。 But if I double click on the Home ribbon button at the upper position the application is closed.
但是,如果我双击上方的“首页”功能区按钮,则该应用程序将关闭。
Could you please tell me if it is standard MFC application handlers behaviour and how I can change it? 您能否告诉我这是否是MFC应用程序处理程序的标准行为,以及如何进行更改?
I've looked at Prevent double click on MFC-Dialog button but couldn't apply it to my case (more clearly - I don't know how to add double click handler to a ribbon home button). 我看过防止在MFC-Dialog按钮上双击,但是无法将其应用于我的情况(更清楚地讲-我不知道如何将双击处理程序添加到功能区主页按钮)。
CMFCRibbonApplicationButton is not derived from CWnd so cannot handle WM_LBUTTONDBLCLK message. CMFCRibbonApplicationButton不是从CWnd派生的,因此无法处理WM_LBUTTONDBLCLK消息。 One solution is to derive from CMFCRibbonBar .
一种解决方案是从CMFCRibbonBar派生。
class CCustomRibbonBar : public CMFCRibbonBar
{
// ...
protected:
DECLARE_MESSAGE_MAP()
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
};
BEGIN_MESSAGE_MAP(CCustomRibbonBar, CMFCRibbonBar)
ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()
void CCustomRibbonBar::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CMFCRibbonBaseElement* pHit = HitTest(point);
if (pHit->IsKindOf(RUNTIME_CLASS(CMFCRibbonApplicationButton)))
{
// the user double-clicked in the application button
// do what you want here but do not call CMFCRibbonBar::OnLButtonDblClk
return;
}
CMFCRibbonBar::OnLButtonDblClk(nFlags, point);
}
Another solution: override PreTranslateMessage in CMainFrame class; 另一种解决方案:在CMainFrame类中重写PreTranslateMessage ;
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if ((WM_LBUTTONDBLCLK == pMsg->message) && (pMsg->hwnd == m_wndRibbonBar))
{
CPoint point(pMsg->pt);
m_wndRibbonBar.ScreenToClient(&point);
CMFCRibbonBaseElement* pHit = m_wndRibbonBar.HitTest(point);
if (pHit && pHit->IsKindOf(RUNTIME_CLASS(CMFCRibbonApplicationButton)))
{
// do what you want but do not call CMDIFrameWndEx::PreTranslateMessage
return TRUE; // no further dispatch
}
}
return CMDIFrameWndEx::PreTranslateMessage(pMsg);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.