Has anybody encountered this issue?
I am using MFC on an MDI application. I switch between menus using SetMenu() but has the side effect of system menus (Maximize, Minimize, Close buttons) disappearing when I maximize the child windows.
CMenu* pMenu = GetMenu();
if (pMenu == NULL) return;
pMenu->Detach();
// Reset application menu
CMenu newMenu;
newMenu.LoadMenu(menuID);
SetMenu(&newMenu);
If I don't call SetMenu(), the issue does not happen.
newMenuis a temporary object. It will be destroyed as soon as the function exits. The result is undefined behavior.I am not sure what this code will accomplish. Note that
CWnd::SetMenuwill replace the old menu. It will not destroy the old menu handle, but MFC will handle the clean up at the end (Detachwill not destroy the handle if that was the goal)Try this code instead:
Declare menu objects as class member:
Load the menu once:
Change menu: