47.1.1 Menu Bars and Pop-up Menus

Menus in a Windows application are arranged hierarchically. A menu bar (sometimes called a top-level menu) resides at the topmost level of the hierarchy; the lower levels consist of pop-up menus (sometimes called submenus).

The items in a menu bar represent the main categories of commands provided by the application. Selecting an item from the menu bar typically invokes a pop-up menu whose items correspond to the commands within a given category. For example, an menu bar might contain a File item that, when the user selects it, would invoke a pop-up menu with items such as New, Open, Save, and so on. The following illustration shows the menu bar and File pop-up menu from the Windows Notepad application.

Only an overlapped or pop-up window can contain a menu bar; a child window cannot. A menu bar is always visible. Windows positions the menu bar just below a window's title bar (if present). By contrast, a pop-up menu is not visible until the user selects a menu item that invokes the pop-up menu. When the pop-up menu is displayed, it is attached to the title bar.

Every menu must have an owner window. Windows sends messages to a menu's owner window when the user selects the menu or chooses a command from the menu. These messages are described in Section 0.1.9, “Menu Messages.”

47.1.1.1 Floating Pop-up Menus

Windows provides a special type of pop-up menu called a floating pop-up menu. A floating pop-up menu isn't attached to the menu bar; it can appear anywhere on the screen. An application typically associates a floating pop-up menu with a portion of a window such as the client area, or with a specific object such as an icon.

A floating pop-up menu remains hidden until the user selects it (for example, by clicking the appropriate location with the mouse.) A floating pop-up menu is typically displayed at the position of the caret or mouse cursor.

47.1.1.2 The System Menu

A System menu is a pop-up menu that is defined and managed almost exclusively by the system. A System menu is represented by a small box containing a horizontal line; the box is displayed at the left end of the title bar. When the user clicks the box, Windows displays the System menu. Windows also displays the System menu when the user clicks the icon of a minimized application.

A System menu contains a standard set of menu items that let the user set a window's size or position, close the application, or invoke the Task List. You can add, delete, and modify items in a System menu, although most applications don't. The following illustration shows a System Menu with the standard menu items.

You can include a System menu in an overlapped, pop-up, or child window. (It is unusual for an overlapped or pop-up window not to include a System menu.)

When the user chooses a command from a System menu, Windows sends a WM_SYSCOMMAND message to the menu's owner window. In most applications, the window procedure doesn't process messages from a System menu. Instead, it simply passes the messages to the DefWindowProc function, which carries out the system-default processing for the message. Although, if you add a command to a System menu, you'll need to process the command in your window procedure.