From 21f204b0167ebfdc41f8fbbda41f4784034fe106 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Thu, 2 Nov 2017 22:17:55 +0100 Subject: [PATCH] Copy code from CMFCMenuButton::OnShowMenu() But drop afxContextMenuManager code. Signed-off-by: Sven Strickroth --- src/Utils/MiscUI/MenuButton.cpp | 69 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/src/Utils/MiscUI/MenuButton.cpp b/src/Utils/MiscUI/MenuButton.cpp index 515f4b76c..2d4abcd93 100644 --- a/src/Utils/MiscUI/MenuButton.cpp +++ b/src/Utils/MiscUI/MenuButton.cpp @@ -193,7 +193,74 @@ void CMenuButton::OnDraw(CDC* pDC, const CRect& rect, UINT uiState) void CMenuButton::OnShowMenu() { m_bRealMenuIsActive = true; - CMFCMenuButton::OnShowMenu(); + + // Begin CMFCMenuButton::OnShowMenu() + if (m_hMenu == NULL || m_bMenuIsActive) + { + return; + } + + CRect rectWindow; + GetWindowRect(rectWindow); + + int x, y; + + if (m_bRightArrow) + { + x = rectWindow.right; + y = rectWindow.top; + } + else + { + x = rectWindow.left; + y = rectWindow.bottom; + } + + if (m_bStayPressed) + { + m_bPushed = TRUE; + m_bHighlighted = TRUE; + } + + m_bMenuIsActive = TRUE; + Invalidate(); + + m_nMenuResult = ::TrackPopupMenu(m_hMenu, TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD, x, y, 0, GetSafeHwnd(), NULL); + + CWnd* pParent = GetParent(); + +#ifdef _DEBUG + if ((pParent->IsKindOf(RUNTIME_CLASS(CDialog))) && (!pParent->IsKindOf(RUNTIME_CLASS(CDialogEx)))) + { + TRACE(_T("CMFCMenuButton parent is CDialog, should be CDialogEx for popup menu handling to work correctly.\n")); + } +#endif + + if (m_nMenuResult != 0) + { + //------------------------------------------------------- + // Trigger mouse up event(to button click notification): + //------------------------------------------------------- + if (pParent != NULL) + { + pParent->SendMessage(WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(), BN_CLICKED), (LPARAM)m_hWnd); + } + } + + m_bPushed = FALSE; + m_bHighlighted = FALSE; + m_bMenuIsActive = FALSE; + + Invalidate(); + UpdateWindow(); + + if (m_bCaptured) + { + ReleaseCapture(); + m_bCaptured = FALSE; + } + // End CMFCMenuButton::OnShowMenu() + m_bRealMenuIsActive = false; } -- 2.11.4.GIT