Replacing a Menu

You can replace a window's menu by using the SetMenu function. Typically, you replace a menu when the application changes modes and needs 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 for restoring the menu later. The SetMenu function replaces the spreadsheet menu with a charting menu loaded from the application's resources.

HMENU hMenu;

HMENU hSpreadsheetMenu;

.

.

.

hOldMenu = GetMenu(hWnd);

hMenu = LoadMenu(hInstance, “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).