7.5.7 Replacing Menus

You can replace menus by using the SetMenu function. Typically, you replace a menu when the application changes modes and requires a completely new set of commands. For example, an application might replace a spreadsheet menu with a charting menu when the user changes from a spreadsheet to a charting mode.

In the following example, the GetMenu function retrieves the menu handle of the spreadsheet menu and saves it in order for it to be restored later. The SetMenu function replaces the spreadsheet menu with a charting menu loaded from the application's resources.

HMENU hMenu, hOldMenu;
HMENU hSpreadsheetMenu;
    .
    .
    .

hOldMenu = GetMenu(hWnd);
hMenu = LoadMenu(hinst, "ChartMenu");
SetMenu(hWnd, hMenu);
    .
    .
    .

You can also load menus from resources other than those belonging to the application (by using the module handle of a library).