we must use TB_BUTTONSTRUCTSIZE before adding menu items to the toolbar; also send SHCMBM_GETMENU after creating the menus, otherwise it always returns NULL

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47816 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-07-29 13:56:05 +00:00
parent d94de683a6
commit 2e297951cd

View File

@@ -927,41 +927,41 @@ WXHMENU wxMenuBar::Create()
if ( m_hMenu != 0 ) if ( m_hMenu != 0 )
return m_hMenu; return m_hMenu;
if (!GetToolBar()) wxToolMenuBar * const bar = wx_static_cast(wxToolMenuBar *, GetToolBar());
return 0; if ( !bar )
return NULL;
HWND hCommandBar = (HWND) GetToolBar()->GetHWND(); HWND hCommandBar = GetHwndOf(bar);
HMENU hMenu = (HMENU)::SendMessage(hCommandBar, SHCMBM_GETMENU, (WPARAM)0, (LPARAM)0);
// notify comctl32.dll about the version of the headers we use before using
// any other TB_XXX messages
SendMessage(hCommandBar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
// hMenu may be zero on Windows Mobile 5. So add the menus anyway.
if (1) // (hMenu)
{
TBBUTTON tbButton; TBBUTTON tbButton;
memset(&tbButton, 0, sizeof(TBBUTTON)); wxZeroMemory(tbButton);
tbButton.iBitmap = I_IMAGENONE; tbButton.iBitmap = I_IMAGENONE;
tbButton.fsState = TBSTATE_ENABLED; tbButton.fsState = TBSTATE_ENABLED;
tbButton.fsStyle = TBSTYLE_DROPDOWN | TBSTYLE_NO_DROPDOWN_ARROW | TBSTYLE_AUTOSIZE; tbButton.fsStyle = TBSTYLE_DROPDOWN |
TBSTYLE_NO_DROPDOWN_ARROW |
TBSTYLE_AUTOSIZE;
size_t i; for ( unsigned i = 0; i < GetMenuCount(); i++ )
for (i = 0; i < GetMenuCount(); i++)
{ {
HMENU hPopupMenu = (HMENU) GetMenu(i)->GetHMenu() ; HMENU hPopupMenu = (HMENU) GetMenu(i)->GetHMenu();
tbButton.dwData = (DWORD)hPopupMenu; tbButton.dwData = (DWORD)hPopupMenu;
wxString label = wxStripMenuCodes(GetLabelTop(i)); wxString label = wxStripMenuCodes(GetLabelTop(i));
tbButton.iString = (int) label.wx_str(); tbButton.iString = (int) label.wx_str();
int position = i;
tbButton.idCommand = NewControlId(); tbButton.idCommand = NewControlId();
if (!::SendMessage(hCommandBar, TB_INSERTBUTTON, position, (LPARAM)&tbButton)) if ( !::SendMessage(hCommandBar, TB_INSERTBUTTON, i, (LPARAM)&tbButton) )
{ {
wxLogLastError(wxT("TB_INSERTBUTTON")); wxLogLastError(wxT("TB_INSERTBUTTON"));
} }
} }
}
m_hMenu = (WXHMENU) hMenu; m_hMenu = bar->GetHMenu();
return m_hMenu; return m_hMenu;
#else #else // !__WXWINCE__
if ( m_hMenu != 0 ) if ( m_hMenu != 0 )
return m_hMenu; return m_hMenu;
@@ -987,7 +987,7 @@ WXHMENU wxMenuBar::Create()
} }
return m_hMenu; return m_hMenu;
#endif #endif // __WXWINCE__/!__WXWINCE__
} }
int wxMenuBar::MSWPositionForWxMenu(wxMenu *menu, int wxpos) int wxMenuBar::MSWPositionForWxMenu(wxMenu *menu, int wxpos)