Menus are used to control applications. Most of the GUI development systems provide an assisted method to define hierarchical menus.

By convention, any selection which opens a dialog box ends with three dots (e.g. Open...).

The standard menu options are

      File         Edit        Help
        New          Undo        
        Open...      -----       --------
        Save         Cut         About...
        Save As...   Copy
        -------      Paste
        Print...     -----
You should use Notepad as a guide.

When referring to a menu selection, list all options from the top of the hierarchy - File/Open...

Visual Basic | Delphi | C++ Builder

Visual Basic 6.0

Select Tools/Menu Editor...
The keyboard shortcut is Ctrl-E

The menu editor can be explicitly opened to make modifications. Properties of individual menu options can be modified using the Properties window - just select the desired menu from the Properties window pull-down.

Cut, Copy, Paste, and Delete

I am trying to generate generic code which implements cut, copy, paste, and delete on text objects.
can access the selected text, but how do I know if the ActiveControl is a text box and not a button? Well Screen.ActiveControl returns a control. However, there is no built-in help for control - no members, no properties, no parent, nothing. Neither the help file nor the fabulous Object Browser provides any information.

The help for ActiveControl contains a partial answer: TypeOf returns the object's type. However, the help for the TypeOf keyword points to If..Then..Else and provides no additional help at all. (The help for VB 3.0 and VB 6.0 are equally bad.) Additional TypeOf help is provided under Clipboard / checking data formats.

In order to control whether or not the menu selections are enabled, it is necessary for all editable UI Controls to add calls to UIMenu_Edit_Set_Enabled in the following events.

Form_Activate Executed when the form starts
xx_UITextBox_Click Triggered when the mouse selects text
xx_UITextBox_GotFocus Required for when the user Tabs into the control
xx_UITextBox_KeyUp Triggered when the keyboard changes the selection (shift cursor key)
xx_UITextBox_LostFocus The next active control may be a button or some other control which does not have a SelLength property. If so, this call will disable the menu selections.

There does not appear to be a way for events to bubble up and be handled at one place for all components. Instead, each editable component must add 4 calls to UIMenu_Edit_Set_Enabled, otherwise there will be problems. (Click on a TextBox with these calls, then click on another TextBox without these calls. Notice that Paste is still active. Now click on a button and then Edit/Paste. There will be an error.)


It would make a lot more sense if the UI Controls had built-in overloaded virtual functions which handled these basic commands.

The whole point of object oriented programming is that you can treat an unknown object as a base object in the class hierarchy and execute overloaded methods without knowing, or caring, what the specific type of the object is.

VB 6.0 fails totally as an object oriented language.

Pop-up Menus

Visual Basic uses the regular menu builder to define pop-up menus (those that appear when you right click something). Simply add a top level menu option and make sure that Visible is false.

The following code is from the VB 6 help ("pop-up menus / displaying"). It pops up a menu when the right mouse button is released.

I suggest using a more descriptive name, like UIPopUpMenu_File.


Place a MainMenu component on the form
Double click the component to open the menu editor.
Properties of individual menu options can be modified using the Object Inspector - just click on the desired menu option. The main properties are Caption (what is shown), Name, and ShortCut (such as Ctrl-Ins).

Actions - Cut, Copy, Paste, and Delete

Menu functions are frequently executed via a variety of controls. For instance, in most applications Copy can be executed by a hot key (Ctrl-Ins), a button on the toolbar, or a menu selection. By using Actions (place a TActionList on your form), you can simplify your code.

Many common actions are already defined.


When either a MainMenu or a PopupMenu component is placed on a form, you double click it to open the Menu Designer dialog box. Right click this dialog box to open the Insert From Template dialog box. A variety of "templates" are available.

Notice that these templates do not assign actions or provide any code - you must manually define what each one of the selections actually does.

It appears that these templates are stored in

If you use Actions, then the default menu templates should not be used.

C++ Builder

This is similar to Delphi.

Author: Robert Clemenzi -
URL: http:// / user / clemenzi / technical / Languages / Menus.htm