+void MDIInsertWindowMenu(wxWindow *win, WXHMENU hMenu, HMENU menuWin)
+{
+ HMENU hmenu = (HMENU)hMenu;
+
+ if ( menuWin )
+ {
+ // Try to insert Window menu in front of Help, otherwise append it.
+ int N = GetMenuItemCount(hmenu);
+ bool inserted = false;
+ for ( int i = 0; i < N; i++ )
+ {
+ wxChar buf[256];
+ if ( !::GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
+ {
+ wxLogLastError(wxT("GetMenuString"));
+
+ continue;
+ }
+
+ const wxString label = wxStripMenuCodes(buf);
+ if ( label == wxGetStockLabel(wxID_HELP, wxSTOCK_NOFLAGS) )
+ {
+ inserted = true;
+ ::InsertMenu(hmenu, i, MF_BYPOSITION | MF_POPUP | MF_STRING,
+ (UINT_PTR)menuWin,
+ wxString(wxGetTranslation(WINDOW_MENU_LABEL)).t_str());
+ break;
+ }
+ }
+
+ if ( !inserted )
+ {
+ ::AppendMenu(hmenu, MF_POPUP,
+ (UINT_PTR)menuWin,
+ wxString(wxGetTranslation(WINDOW_MENU_LABEL)).t_str());
+ }
+ }
+
+ MDISetMenu(win, hmenu, menuWin);
+}
+
+void MDIRemoveWindowMenu(wxWindow *win, WXHMENU hMenu)
+{
+ HMENU hmenu = (HMENU)hMenu;
+
+ if ( hmenu )
+ {
+ wxChar buf[1024];
+
+ int N = ::GetMenuItemCount(hmenu);
+ for ( int i = 0; i < N; i++ )
+ {
+ if ( !::GetMenuString(hmenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
+ {
+ // Ignore successful read of menu string with length 0 which
+ // occurs, for example, for a maximized MDI child system menu
+ if ( ::GetLastError() != 0 )
+ {
+ wxLogLastError(wxT("GetMenuString"));
+ }
+
+ continue;
+ }
+
+ if ( wxStrcmp(buf, wxGetTranslation(WINDOW_MENU_LABEL)) == 0 )
+ {
+ if ( !::RemoveMenu(hmenu, i, MF_BYPOSITION) )
+ {
+ wxLogLastError(wxT("RemoveMenu"));
+ }
+
+ break;
+ }
+ }
+ }
+
+ if ( win )
+ {
+ // we don't change the windows menu, but we update the main one
+ MDISetMenu(win, hmenu, NULL);
+ }
+}
+
+void UnpackMDIActivate(WXWPARAM wParam, WXLPARAM lParam,
+ WXWORD *activate, WXHWND *hwndAct, WXHWND *hwndDeact)
+{
+ *activate = true;
+ *hwndAct = (WXHWND)lParam;
+ *hwndDeact = (WXHWND)wParam;
+}
+
+} // anonymous namespace
+
+#endif // wxUSE_MDI && !defined(__WXUNIVERSAL__)