From 6ea435350e4353f689d259b336adee7cc2247eba Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 10 Sep 2014 16:51:33 +0000 Subject: [PATCH] Avoid generating wxEVT_MENU_OPEN and CLOSE for disabled menus in wxMSW. Check if a top level menu is disabled and consume WM_[UN]INITMENUPOPUP that Windows still generates for it when it's clicked for some reason. Closes #2168. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77657 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/frame.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index af928e4536..1f252b534d 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -990,6 +990,47 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara } break; #endif // !__WXMICROWIN__ + +#if wxUSE_MENUS + case WM_INITMENUPOPUP: + { + wxMenuBar* const bar = GetMenuBar(); + if ( bar && !bar->IsEnabledTop(LOWORD(lParam)) ) + { + // Skip sending of wxEVT_MENU_OPEN in the base class + // MSWWindowProc() for disabled top level menus. + return MSWDefWindowProc(message, wParam, lParam); + } + } + break; + + case WM_UNINITMENUPOPUP: + { + wxMenuBar* const bar = GetMenuBar(); + if ( !bar ) + break; + + // Unlike in WM_INITMENUPOPUP above, we don't have the position + // of the menu in the message itself, so find it ourselves. + const HMENU hmenu = (HMENU)wParam; + + const size_t count = bar->GetMenuCount(); + for ( size_t n = 0; n < count; n++ ) + { + wxMenu* const menu = bar->GetMenu(n); + if ( GetHmenuOf(menu) == hmenu ) + { + if ( !bar->IsEnabledTop(n) ) + { + // If we skipped sending wxEVT_MENU_OPEN, don't + // send wxEVT_MENU_CLOSE neither. + return MSWDefWindowProc(message, wParam, lParam); + } + } + } + } + break; +#endif // wxUSE_MENUS } #if wxUSE_TASKBARBUTTON if ( message == wxMsgTaskbarButtonCreated )