From: Vadim Zeitlin Date: Sat, 31 Jan 2009 22:46:43 +0000 (+0000) Subject: allow calling SetItemLabel() for items not attached to the menu or menu bar yet ... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5c6aad4737c43ad32408132ab5e927679393c47e allow calling SetItemLabel() for items not attached to the menu or menu bar yet (comment 9 of #10452) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58574 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 13a28675cd..e31925031e 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -358,13 +358,18 @@ void wxMenuItem::SetItemLabel(const wxString& txt) SetAccelString(m_text.AfterFirst(_T('\t'))); #endif - HMENU hMenu = GetHMenuOf(m_parentMenu); - wxCHECK_RET( hMenu, wxT("menuitem without menu") ); - #if wxUSE_ACCEL - m_parentMenu->UpdateAccel(this); + if ( m_parentMenu ) + m_parentMenu->UpdateAccel(this); #endif // wxUSE_ACCEL + // the item can be not attached to any menu yet and SetItemLabel() is still + // valid to call in this case and should do nothing else + const UINT id = GetMSWId(); + HMENU hMenu = GetHMenuOf(m_parentMenu); + if ( !hMenu || ::GetMenuState(hMenu, id, MF_BYCOMMAND) == (UINT)-1 ) + return; + #if wxUSE_OWNER_DRAWN if ( IsOwnerDrawn() ) { @@ -375,8 +380,6 @@ void wxMenuItem::SetItemLabel(const wxString& txt) #endif // owner drawn // update the text of the native menu item - const UINT id = GetMSWId(); - WinStruct info; // surprisingly, calling SetMenuItemInfo() with just MIIM_STRING doesn't