From c70ffbdbf064d5689792c8f0d90d8032d2c1198a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 13 Jan 2006 21:03:19 +0000 Subject: [PATCH] fixed crash with ownerdrawn menu items accelerators (Perry Miller) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36863 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/window.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 328ed2c45e..a19651b105 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -57,6 +57,7 @@ All (GUI): wxMSW: +- Fixed crash with ownerdrawn menu items accelerators (Perry Miller) - wxFileDialog respects absence of wxCHANGE_DIR flag under NT (Brad Anderson). - Switching page of a hidden notebook doesn't lose focus (Jamie Gadd). - Removed wxImageList *GetImageList(int) const. diff --git a/src/msw/window.cpp b/src/msw/window.cpp index a50831dea8..140dd8f88d 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -4893,12 +4893,20 @@ int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel), MENUITEMINFO mii; wxZeroMemory(mii); mii.cbSize = sizeof(MENUITEMINFO); + + // we could use MIIM_FTYPE here as we only need to know if the item is + // ownerdrawn or not and not dwTypeData which MIIM_TYPE also returns, but + // MIIM_FTYPE is not supported under Win95 mii.fMask = MIIM_TYPE | MIIM_DATA; // find if we have this letter in any owner drawn item const int count = ::GetMenuItemCount(hmenu); for ( int i = 0; i < count; i++ ) { + // previous loop iteration could modify it, reset it back before + // calling GetMenuItemInfo() to prevent it from overflowing dwTypeData + mii.cch = 0; + if ( ::GetMenuItemInfo(hmenu, i, TRUE, &mii) ) { if ( mii.fType == MFT_OWNERDRAW ) @@ -4936,8 +4944,7 @@ int wxWindowMSW::HandleMenuChar(int WXUNUSED_IN_WINCE(chAccel), } else // failed to get the menu text? { - // it's not fatal, so don't show error, but still log - // it + // it's not fatal, so don't show error, but still log it wxLogLastError(_T("GetMenuItemInfo")); } } -- 2.45.2