- 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 = m_menus[i]->m_vMenuData.hwndSubMenu;
+ if (!::WinSetParent(m_menus[i]->m_vMenuData.hwndSubMenu, m_hMenu, FALSE))
+ {
+ vError = ::WinGetLastError(vHabmain);
+ sError = wxPMErrorToStr(vError);
+ wxLogError("Error setting parent for submenu. Error: %s\n", sError);
+ return NULLHANDLE;
+ }
+
+ if (!::WinSetOwner(m_menus[i]->m_vMenuData.hwndSubMenu, m_hMenu))
+ {
+ vError = ::WinGetLastError(vHabmain);
+ sError = wxPMErrorToStr(vError);
+ wxLogError("Error setting parent for submenu. Error: %s\n", sError);
+ return NULLHANDLE;
+ }
+
+ m_menus[i]->m_vMenuData.iPosition = i;
+
+ rc = (APIRET)::WinSendMsg(m_hMenu, MM_INSERTITEM, (MPARAM)&m_menus[i]->m_vMenuData, (MPARAM)m_titles[i].c_str());
+ if (rc == MIT_MEMERROR || rc == MIT_ERROR)
+ {
+ vError = ::WinGetLastError(vHabmain);
+ sError = wxPMErrorToStr(vError);
+ wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError);
+ return NULLHANDLE;
+ }