CMenu* pOldMenu = pWnd->GetMenu(); // Get the current menu of the window pWnd->SetMenu(NULL); // Set the window's menu to NULL, detaching it delete pOldMenu; // Delete the old menu object
CMenu* pOldMenu = pWnd->GetMenu(); // Get the current menu of the window CMenu newMenu; newMenu.LoadMenu(IDR_NEW_MENU); // Load a new menu from resources pWnd->SetMenu(&newMenu); // Set the new menu as the window's menu delete pOldMenu; // Delete the old menu objectIn this example, we first retrieve the current menu object of a window. We then load a new menu from resources using the `LoadMenu()` function and store it in a new `CMenu` object. We set the new `CMenu` object as the window's menu using the `SetMenu()` function. Finally, we delete the old menu object using the `delete` operator. The `CMenu` class is part of the MFC (Microsoft Foundation Classes) library, which is a set of C++ classes provided by Microsoft for building Windows-based applications.