diff --git a/include/wx/msw/menuitem.h b/include/wx/msw/menuitem.h index 64b1b75cd5..5c6b20546b 100644 --- a/include/wx/msw/menuitem.h +++ b/include/wx/msw/menuitem.h @@ -149,6 +149,12 @@ private: wxBitmapBundle m_bmpDisabled; #endif // wxUSE_OWNER_DRAWN + // Bitmaps being currently used: we must store them separately from the + // bundle itself because their HBITMAPs must remain valid as long as + // they're used by Windows. + wxBitmap m_bmpCheckedCurrent, + m_bmpUncheckedCurrent; + // Give wxMenu access to our MSWMustUseOwnerDrawn() and GetHBitmapForMenu(). friend class wxMenu; diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 38e249d743..d40a433142 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -1369,8 +1369,12 @@ HBITMAP wxMenuItem::GetHBitmapForMenu(BitmapKind kind) const #if wxUSE_IMAGE if ( wxGetWinVersion() >= wxWinVersion_Vista ) { + // We need to store the returned bitmap, so that its HBITMAP remains + // valid for as long as it's used. bool checked = (kind != Unchecked); - wxBitmap bmp = GetBitmap(checked); + wxBitmap& bmp = const_cast(checked ? m_bmpCheckedCurrent + : m_bmpUncheckedCurrent); + bmp = GetBitmap(checked); if ( bmp.IsOk() ) { return GetHbitmapOf(bmp);