+ if ( pItem->IsOwnerDrawn() )
+ {
+ // is the item owner-drawn just because of the bitmap?
+ if ( pItem->GetBitmap().Ok() &&
+ !pItem->GetTextColour().Ok() &&
+ !pItem->GetBackgroundColour().Ok() &&
+ !pItem->GetFont().Ok() &&
+ !pItem->GetBitmap(true).Ok() )
+ {
+ // try to use InsertMenuItem() as it's guaranteed to look correctly
+ // while our owner-drawning code is not
+
+ // first compile-time check
+#ifdef MIIM_BITMAP
+ WinStruct<MENUITEMINFO> mii;
+
+ // now run-time one: MIIM_BITMAP only works under WinME/2000+
+ if ( wxGetWinVersion() >= wxWinVersion_98 )
+ {
+ mii.fMask = MIIM_STRING | MIIM_DATA | MIIM_BITMAP;
+ mii.cch = itemText.length();
+ mii.dwTypeData = wx_const_cast(wxChar *, itemText.c_str());
+
+ if (flags & MF_POPUP)
+ {
+ mii.fMask |= MIIM_SUBMENU;
+ mii.hSubMenu = (HMENU)pItem->GetSubMenu()->GetHMenu();
+ }
+ else
+ {
+ mii.fMask |= MIIM_ID;
+ mii.wID = id;
+ }
+
+ // we can't pass HBITMAP directly as hbmpItem for 2 reasons:
+ // 1. we can't draw it with transparency then (this is not
+ // very important now but would be with themed menu bg)
+ // 2. worse, Windows inverses the bitmap for the selected
+ // item and this looks downright ugly
+ //
+ // so instead draw it ourselves in MSWOnDrawItem()
+ mii.dwItemData = wx_reinterpret_cast(ULONG_PTR, pItem);
+ mii.hbmpItem = HBMMENU_CALLBACK;
+
+ ok = ::InsertMenuItem(GetHmenu(), pos, TRUE /* by pos */, &mii);
+ if ( !ok )
+ {
+ wxLogLastError(wxT("InsertMenuItem()"));
+ }
+ else // InsertMenuItem() ok
+ {
+ // we need to remove the extra indent which is reserved for
+ // the checkboxes by default as it looks ugly unless check
+ // boxes are used together with bitmaps and this is not the
+ // case in wx API
+ WinStruct<MENUINFO> mi;
+
+ // don't call SetMenuInfo() directly, this would prevent
+ // the app from starting up under Windows 95/NT 4
+ typedef BOOL (WINAPI *SetMenuInfo_t)(HMENU, MENUINFO *);
+
+ wxDynamicLibrary dllUser(_T("user32"));
+ wxDYNLIB_FUNCTION(SetMenuInfo_t, SetMenuInfo, dllUser);
+ if ( pfnSetMenuInfo )
+ {
+ mi.fMask = MIM_STYLE;
+ mi.dwStyle = MNS_CHECKORBMP;
+ if ( !(*pfnSetMenuInfo)(GetHmenu(), &mi) )
+ wxLogLastError(_T("SetMenuInfo(MNS_NOCHECK)"));
+ }
+
+ // tell the item that it's not really owner-drawn but only
+ // needs to draw its bitmap, the rest is done by Windows
+ pItem->ResetOwnerDrawn();
+ }
+ }
+#endif // MIIM_BITMAP
+ }
+
+ if ( !ok )
+ {
+ // item draws itself, pass pointer to it in data parameter
+ flags |= MF_OWNERDRAW;
+ pData = (LPCTSTR)pItem;
+ }