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

How To Create Pop-up Menu in C++ Builder?

How can I create visual menus in C++? What is a Pop-up menu? Which C++ IDE supports the ability to create menus? How can I create a visual Popup Menu in C++? What is TPopupMenu? What is TMenuItem? What kind of menus I can create?

What is Menu in Programming?

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 with minimal ‘screen clutter’. If you are developing professional applications and you have a lot of categories, actions, forms, or modules you may need to use menus to reduce the number of visual items on a screen and to provide an easy way to navigate between the sections. Many great applications like RAD Studio, Word, Excel, PowerPoint and Photoshop have these menus. These kinds of applications cannot let users achieve actions easily by other means. In the last decade, we see more modern menus, like corner radial buttons. Still, classic menus are easy to reach and make it simpler to perform a desired action.

Menus are easy to navigate and find actions in their categories, we call these categories Menu Items. In C++ Builder, developing menus is very easy by using TMainMenu in both VCL and FireMonkey applications. Let’s see how we can use standard menus in C++ Builder.

What kind of menu control types are available?

Main Menu: The most used version is the MainMenu (TMainMenu). Simply you can add vertical and horizontal 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 or right 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 on the image 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 display 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. The hamburger menu (so called because it often has three stacked horizontal lines which look like a hamburger) is an example of a corner menu.

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 and menus for authorized persons.

What kind of program navigation menus can be created in C++ Builder apps?

Actually, in C++ Builder there is no limit to menus. 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 do we use to create a main program 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, and double-click the component. 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 does a popup menu do?

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. This type of menu is sometimes called a “context menu” since it “pops up” near a specific control and generally relates to some kind of action – or context – that applies to the control over which it appeared.

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 can I create a popup 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 TPopupMenu component from Palette window to the form design. It will be named PopupMenu1, you can change its name from Object Inspector if you want.
  3. Double click to PopupMenu1 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 “New Project …” as in the example below
How To Create Pop up Menu in C++ Builder Creating a Popup menu

5. We can add new menu items to our popup menu. Here we added some more items as below,

How To Create Pop up Menu in C++ Builder Populating the popup menu

6. Now we can set this our Popup Menu to a component or to the Form itself. Let’s add a TImage component, arrange it on the form. Select TImage1 component, In the Object Inspector, there is Popup Menu property in Properties tab. Select PopupMenu1 (or your popup menu name). This will automatically add right mouse button action on this component.

7. Press F9 or Run button to run the application. If you right click the

How To Create Pop up Menu in C++ Builder Popup menu

Here is the final result when we use the right mouse button click on the Image1 component.

How To Create Pop up Menu in C++ Builder A popup menu in action

How can I Invoke a popup menu in C++ Builder, for example, with a left mouse button click ?

If you want you can Popup this menu in anytime on any place of the screen by giving X and Y coordinates on the screen. For example, if you want to do same action on the Left Mouse Button click, you must add this the OnMouseDown() event of the component as below,

How can I create events for Popup 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 Pop Menu
  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 the “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 C++ Builder is very easy to build Popup Menus, it is also easy to do the same ways on the Main Menus. You can also use other components to do some specific menus for your applications. Note that C++ Builder has great Styles for its application. 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
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

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

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

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

How To Learn The Move Constructors In Modern C++?