- vItem.iPosition = 0;
- vItem.afStyle = MIS_SUBMENU | MIS_TEXT;
- vItem.afAttribute = (USHORT)0;
- vItem.id = (USHORT)0;
- vItem.hwndSubMenu = m_menus[i]->GetHMenu();
- vItem.hItem = NULLHANDLE;
-
- ::WinSendMsg(GetHmenu(), MM_INSERTITEM, (MPARAM)&vItem, (MPARAM)m_titles[i].c_str());
+ APIRET rc;
+ ERRORID vError;
+ wxString sError;
+ HWND hSubMenu;
+
+ //
+ // Set the parent and owner of the submenues to be the menubar, not the desktop
+ //
+ hSubMenu = (*it)->m_vMenuData.hwndSubMenu;
+ if (!::WinSetParent((*it)->m_vMenuData.hwndSubMenu, m_hMenu, FALSE))
+ {
+ vError = ::WinGetLastError(vHabmain);
+ sError = wxPMErrorToStr(vError);
+ wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError.c_str());
+ return NULLHANDLE;
+ }
+
+ if (!::WinSetOwner((*it)->m_vMenuData.hwndSubMenu, m_hMenu))
+ {
+ vError = ::WinGetLastError(vHabmain);
+ sError = wxPMErrorToStr(vError);
+ wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError.c_str());
+ return NULLHANDLE;
+ }
+
+ (*it)->m_vMenuData.iPosition = (SHORT)i;
+
+ rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&(*it)->m_vMenuData, (MPARAM)m_titles[i].c_str());
+ if (rc == (APIRET)MIT_MEMERROR || rc == (APIRET)MIT_ERROR)
+ {
+ vError = ::WinGetLastError(vHabmain);
+ sError = wxPMErrorToStr(vError);
+ wxLogError(wxT("Error inserting or appending a menuitem. Error: %s\n"), sError.c_str());
+ return NULLHANDLE;
+ }