C++ComponentsIntroduction to C++Learn C++

Everything You Need To Know To Create Menus In C++ Builder

Everything You Need To Know To Create Menus in C++ Builder

How can I create visual menus in C++? Which C++ IDE supports to create Menus easily? How can I use Main Menu easily with a C++ compiler code? What is TMainMenu? What is TMenuItem? What kind of menus I can create in C++?

What is a “Menu” in an application?

Menus are one of the most important parts of professional applications. If you are developing a small application you may prefer implied UI designs. Nowadays simplified UI designs are preferred and developers avoid using menus to make their application simple and easy. If you are developing professional applications, and if you have a lot of categories, actions, forms, modules, .. you need to use menus. Many great applications like RAD Studio, Word, Excel, PowerPoint, Photoshop, Coreldraw, StudioMax,… have these menus and these kinds of applications can not let users achieve actions easily by other means. In the last decade there has a trend towards more modern menus, like corner radial buttons, etc. Still, classic menus are easy to reach and easy to find.

Menus are easy to navigate. In C++ Builder, developing menus is very easy by using TMainMenu in both VCL and FireMonkey applications. Now let’s see how we can use standard menus in C++ Builder.

What kind of menu types can I create in my programs?

Main Menu: The most used version is the MainMenu (TMainMenu). Simply you can add vertically and horizontally menu items and actions for them, generally, they stand at the top of the application window in a menu bar.

Popup Menu: Popup menus (TpopupMenu) are menus that pop when an action is performed by the user. This kind of menu generally pops up when the user clicks on a component or on a specific area. Thus, you can create different popup menus for the different components, areas, and actions of users.

Zone Menu: If you have fewer categories, you can use buttons, texts, images, or zone areas (like Layouts, Panels, Rectangles, Circles) on the form or image background as a menu. This kind is generally used in games and in small applications.

Corner Menu: This kind of menu is generally placed in the corner of the area, to make less space for the menu and more space for the UI. They can pop up in vertical, horizontal, or in radial modes. Generally, these are custom menus developed by developers or supported by 3rd party applications.

Text Input Menu: In some cases, writing menu actions can be easy to achieve the action fast. Not practical but can be used in some applications, text-based games, text commands, menus for authorized persons, etc. For example AutoCAD LISP commands had these kind of menus for setting CAD properties..

What kind of menus can be used in C++ Builder?

Actually, in C++ Builder menus are not limited. You can create your own custom menus with amazing UI designs. You can create standard menus or you can use other new component features as a menu, or more you can create 3D menus in a 3D environment. Everything is possible in C++, only the device and device properties may limit your designs.

What is a main menu in C++ Builder?

TMainMenu encapsulates a menu bar and its accompanying drop-down menus for a form. We can use TMainMenu to provide the main menu for a form. To begin designing a menu, add the main menu to a form just like any other component. Now double-click the menu component you dropped on the form. TMainMenu introduces properties and methods for merging the drop-down menus of the main menu with the main menu of another form. TMainMenu introduces properties and methods for assisting in the menu negotiation process of an OLE container.

Tip: To create a menu that users can configure at runtime, use the TActionMainMenuBar component with an action manager instead.

What is a popup menu in C++ Builder?

TPopupMenu encapsulates the properties, methods, and events of a pop-up menu. We can use TPopupMenu to define the pop-up menu that appears when the user clicks on a control with the right mouse button. To make a pop-up menu available, assign the TPopupMenu object to the control’s PopupMenu property. These kind of menus are sometimes called “context” or “context sensitive” menus because they tend to be associated with a particular parent or owner control and popup when the user right clicks within or on the owner control’s area. The popup menu then shows functions which generally only apply to the parent such as showing lists in a different way or selecting/copying/pasting the contents and other actions.

Tip: To create a popup menu that users can configure at runtime, use the TStandardMenuPopup component with an action manager instead.

Note: If the popup menu’s ParentBiDiMode is true, the popup menu’s BiDiMode is set to the BiDiMode of the control that activates it. If a control cannot be found, the BiDiMode is set to the value of the Application object’s BiDiMode. The popup menu’s BiDiMode affects all of its menu items.

How to create main menu in C++ Builder

  1. In Rad Studio, C++ Builder, create a new VCL project and save all project files to a folder.
  2. Drag TMainMenu component from Palette window to the form design. It will be named MainMenu1, you can change its name from Object Inspector if you want.
  3. Double click to MenuMenu1 to add Menu items
  4. In this window, you will see a small space in a rectangular area, press there and from the Object Inspector, add a caption to this main category. For example “Application Project” as in the example below
Everything You Need To Know To Create Menus in C++ Builder Adding a main menu in the IDE

5. Now you will see two new rectangular spaces. You can create another main category item on the left rectangle or sub categories under the main category that we create. Select the rectangular area under the main category that we create. Here it is under the “Application Project” menu. Click this area as below

Everything You Need To Know To Create Menus in C++ Builder Showing a main menu on a form

Now you can continue to add other sub menus like Load Project, Save Project, Exit etc.. Or you can add new categories from the top rectangle.

Everything You Need To Know To Create Menus in C++ Builder Showing sub menus

How to create events for the Main Menu Items?

In C++ Builder, it is very easy to create events or actions for a menu item. To do this,

  1. Double click to the Main Menu component (i.e MainMenu1)
  2. Select the menu and double-click on it. This will create OnClick() event for this menu item. Or you can manually go to Events of the menu item in Object Inspector and double click to OnClick() event there. Both will create an OnClick event for that menu item. For example, if we double click on “New Project …” menu item we can create its OnClick event as below. Here we show a message when this menu is selected. You can do or execute whatever you want inside this procedure.

As you see it is very easy to build Main Menus in C++ Builder. It is also easy to create popup (context) menus. You can also use other components to create less common types of menus for your applications. Note that C++ Builder has great visual ‘styles’ you can apply to your applications. Each style also affects your menu design too. You just need to select a style for that window or for that menu and it will be displayed on run time. Another professional way is to use actions. You can create actions and you can add the required actions for each menu item.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?

C++C++11Introduction to C++Learn C++Syntax

Full List Of Features In C++ 11

C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

How To Use Basic Methods Of Strings In C++?