When a window is created with the style style::system_menu, the window possesses a system menu. Because style::standard (which is a composite style) includes the style style::system_menu, almost all programs that have been created to this point have such a menu. A system menu is shown below.
As may be observed, a system menu contains:
Whilst all system menus look alike to begin with, they may be altered. Altering the system menu can provide menu options for an application that does not have a resource script. When adding items to a system menu, in order to avoid conflicting with existing item identities, the specified identities should be lower than 0xf000.
The program of this section defines three items to be added to the system menu - shown in the table below.
system_item::about | An "about" menu item which displays a message box. |
system_item::help | A "system help" item which displays a message box. |
system_item::remove | A "remove item" that causes the system menu to revert to normal. |
The above values are defined as an enumerated type - which is shown below.
struct system_item { enum { about=1, help=2, remove=3 }; };
Within the creation message, a new system menu is created - as shown below.
case message::create: { handle menu_handle = get_system_menu(window_handle,false); append_menu(menu_handle,menu_item_flag::Separator,0,(const character*)null); append_menu(menu_handle,menu_item_flag::string,system_item::about, "About..."); append_menu(menu_handle,menu_item_flag::string,system_item::help, "Help..."); append_menu(menu_handle,menu_item_flag::string,system_item::remove, "Remove Additions"); } break;
System menus send the notification message::system_command rather than the notification message::command. When intercepting the system command notifications, the application should pass the notifications corresponding to items not added by the application to the default window procedure. This is done in the code shown below.
case message::system_command: switch(low_part(parameter1)) { case system_item::about: message_box(window_handle, "About System Menus", "System menu Manipulation", message_box_style::ok | message_box_style::icon_information); break; case system_item::help: message_box(window, "help is yet to be implemented!", "System menu Manipulation", message_box_style::ok | message_box_style::IconExclamation); break; case system_item::remove: get_system_menu(window_handle,true); break; default: return default_window_procedure(window_handle,identity,parameter1,parameter2); } break;
The first two notifications: system_item::about and system_item::help display message boxes (with embedded strings - because no resource file exists). The third selection (system_item::remove) causes the standard system menu to be reinstated and the menu that was altered to be destroyed automatically. Finally, the default option calls the default window procedure.