Menu Editor


Available through the Tools-->Menu Editor menu or when adding a menu resource (Project-->Add Resource-->Menu).

When it is open, it shows the window below and allows you to design a menu for the window object being active (only for visual project type). If the menu editor is open by a menu designed as a resource (see Resources), the Accelerator option is not available as Resources have their own Accelerator designer.

In visual projects, each window object may have a menu object. This menu object is the top menu, which is set to the window object (that specified in the caption of the menu Editor) and it is not shown in the menu bar (let's say it is the menu bar). A top menu is a popup menu, which may have other popup menus inside. On the other hand, inside popup menus there are menu items or other popup menus. Those popup menus being in the first level, that is, being directly children of the top menu, will be shown in the menu bar. Other popup or menu items are only shown when their popup parent menu is clicked. A popup menu does not have an identifier because they do not send WM_COMMAND messages to the owner window. Menu items do have an identifier or ID and they are shown when their popup parent menu is clicked. Once shown, we can click on any menu item to perform an action. When clicking on a menu item, it sends a WM_COMMAND message with its ID value in the low word of wParam parameter (high word of wParam is 0). The window receiving this message is the window which the menu is set to. We can easily get the ID constant name for each menu item, just applying the following simple rule:

A menu item constant ID is formed by 'IDM_' plus the upper case name of the Window object, plus '_', plus the text you write in the text box named ID (that text box is not available for popup menus and separators). For example, supose you write EXIT as an ID for a menu item which is inside a menu belonging to a window named wndMain. The constant name for that menu item will be:

IDM_WNDMAIN_EXIT

By default, Easy Code sets each menu to its owner window (that specified in the menu editor's caption at design time) in visual projects. The name of that owner window is used to form the constant ID. If you set a menu to any other window along the code (API function SetMenu), WM_COMMAND messages will be sent to the new owner window of the menu, but its constant ID WILL NOT CHANGE. So, you should use that constant ID along all code for the referred menu item, for example when writing code for it in the WM_COMMAND message of the window object which the menu is set to.

It should look like this:

:   Cmp D[uMsg], WM_COMMAND
    Jne >
    Mov Eax, [wParam] ; Low word of wParam in register Ax
    Cmp Ax, IDM_WNDMAIN_EXIT
    Jne > L2
    ......
    Do something...
    ······
    Return (TRUE)
:   Cmp D[uMsg],
...
    ······
    ······
L2:
    Return (FALSE)

In the menu editor, a line may be a popup menu only when it has menu items, that is, when at least the line immediately after has one more tab (>>). By clicking on forward (>>) and backward (<<) buttons you can design a menu. Every menu item may be checked, disabled or both, and it may have an accelerator key. An accelerator is that key which performs the same operation than clicking on the corresponding menu item. For example, in most applications, pressing the <F1> key is the same than open the Help menu and click on View help menu item. For those menu items you like to appear as separators, write just a hyphen (-) in its caption (text box named Caption). For example, supose we have the following lines:

&File
    >>&Open
    >>&Close
    >>-
    >>Exit

First line (&File) is a popup menu (because four lines after it has one more tab (>>). As it is in the first level (has no tabs), it will appear in the menu bar. When clicked, its four menu items will be shown. The third menu item (fourth line) is a separator. Separators do nothing else than separate menu items. On the other hand, note that ampersands (&) will not be visible in popup menus or menu items, but the character immediately after an ampersand will appear underlined at run time.

Now supose we want to add another popup menu, let's say for example, Edit. We will add the following lines (added lines in bold font):

&File
    >>&Open
    >>&Close
    >>-
    >>Exit

&Edit
    >>&Copy
    >>C&ut
    >>&Paste
    >>&Delete

As you can see, sixth line (&Edit) is backwarded to the same level than first line (&File). It has menu items, so it is a popup menu. As it is in the first level too, it will appear in the menu bar, which will look like this:

File   Edit

After creating a menu, it is easy to write code for its menu items using their constant ID names. For the menu items in the example above, supose we have assigned (in the text box named ID) the following ID's (remember that popup menus and separators have no ID):

&Open    ID:  OPEN
&Close   ID:  
CLOSE
&Exit    ID:  
EXIT
&Copy    ID:  
COPY
C&ut     ID:  
CUT
&Paste   ID:  
PASTE
&Delete  ID:  DELETE

As the top menu belongs to a window named wndMain, all those menu items will have, respectively, the following constant ID names (all upper case):

IDM_WNDMAIN_OPEN
IDM_WNDMAIN_CLOSE
IDM_WNDMAIN_EXIT
IDM_WNDMAIN_COPY
IDM_WNDMAIN_CUT
IDM_WNDMAIN_PASTE
IDM_WNDMAIN_DELETE

Besides, for each menu item, you can assign (or not) an accelerator key in the combo box named Accelerator. When at least one accelerator key is assigned, Easy Code creates an Accelerator table. You can get its handle at run time (only for the main window) through the App.Accel member even though you usually do not need it, as Easy Code also takes care of accelerators in visual projects.

When working with MDI applications (see MDI Applications), take into account that each MDI child window getting active, sets its menu (if any) to the MDI frame window. The MDI frame (an MDIWindow object) will be the owner of that menu, so messages from the menu items will be sent to MDI frame, not to MDI child which originally was the owner of the menu. That does not affect to the menu items constant ID names, which remain being the same. When the MDI child gets inactive, the menu will be set to it again and the MDI frame will get the menu of the new active MDI child window.

IMPORTANT: When the Owner draw check box is selected, the corresponding menu item is not drawn by Windows. Instead, a WM_DRAWITEM message is sent to the parent window for the menu item to be drawn by the application.

NOTE: Everything we have just seen in the lines above is only valid for visual projects type. When the menu editor is open by a menu designed as a resource, the ID for each item is exactly the name specified in the ID text box and the accelerators must be set in the classic way, that is, creating an accelerator table where all keys are assigned to the corresponding menu items.

REMARKS: To be even more flexible, menus (both popup and items) accept string IDentifiers in its Caption (see Resources)

.