Sometimes we often in the program to achieve the heavy painting of menu items, there are many articles have been introduced, here no longer repeat. But sometimes we need to add a new menu item to the System menu, and we want to add a corresponding event to it. By using Windowapi's AppendMenu function and C++buider's related methods and properties, the author realizes adding menu items and events to the system menu.
The following describes the implementation of the following steps, the reader can be implemented in the System menu to add menu items and events:
1 first create a new empty project file, save for Project1.cpp and Unit1.cpp.
2 Using the image Editor in the menu tools, open the resource file Project1, create a new bitmap and name it help.
3 define the following constants as the label for the menu in the header of the source file:
#define IDM_HELP1 1
#define IDM_HELP2 2
#define IDM_REMOVE 3
#define IDM_SEPARATOR1 4
#define IDM_SEPARATOR2 5
4 Create the OnCreate event for Form1, add code implementation adds menu items to the System menu:
First, define the menu handle and the bitmap handle:
Hmenu Hmenu;
Hbitmap Hbitmaphelp;
Then get the handle to the system menu:
Hmenu = GetSystemMenu (This->handle, FALSE);
Add your own menu items to the System menu:
AppendMenu (Hmenu, Mf_separator,idm_separator1, NULL);
AppendMenu (Hmenu, MF_STRING,IDM_HELP1, "help");
AppendMenu (Hmenu, Mf_separator,idm_separator2, NULL);
AppendMenu (Hmenu, Mf_string,idm_remove, "cancel Menu");
Add a bitmap to the menu, load the bitmap resource first, get its handle, and then add it to the system menu:
Hbitmaphelp =loadbitmap ((void*) hinstance, "help");
AppendMenu (Hmenu, MF_BITMAP,IDM_HELP2, (char*) hbitmaphelp);