Add menu items and corresponding events to the system menu

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.