Creating a Menu on An SDI/MDI

1 -

Start Microsoft Visual C++.

2 - a/

Create a Single Document Interface (SDI) or a Multiple Document Interface (MDI), based on CRichEditView and called Notice. You can also use mine, that is, the Notice application created when learning about MDI.


In Visual C++, click the ResourceView tab. Click the + sign on the Notice Resources to expand it.


Whenever you want to use a menu on an application, you have a lot of choices, depending on the application you are trying to create. Since ultimately you will call functions, first find out whether the function you want to use is already part of the MFC, in which case you might not have to write a new one.

The other decision you will have to make is whether to use an already created menu or you want to create a new one.

The application we are going to use is a small tinny word processor and we will try to deal with various aspects involving the menu.


3 -

Creating A New Menu Item

a/ In the ResourceView, click the + sign on the Menu to expand it.
b/ Double-click the IDR_NOTICETYPE menu to open it.
c/ There is an empty dotted box on the right side of the Help menu. Click it and type Format.

That's how you add a menu item on an existing menu. Notice that as you type, Format gets displayed in the Properties dialog.

d/ On the Properties dialog, click the Push Pin button to lock the Properties dialog on top of other windows.
e/ Click the box under Format in the menu. Every menu item needs an identifier that Visual C++ can use when compiling the program. The first menu we are going to use has an already created fully functioning function.
To give an identifier to a menu item, you type it in the ID combo box. If the identifier already exists, you can just select it from the list.
Click the arrow on the ID combo box and start typing ID_FO... An identifier called ID_FORMAT_FONT comes up. Select it from the list and press Tab.
f/ In the Caption box, type Font.
At this time, this menu is completely functional. If you want, build your program now and try to click Format -> Font


4 -

Shortcuts And Good Habits

It is a good tradition to keep the Help menu as the most right menu on the menu bar. Frankly, it is better that way; so, we need to move our menu.

As a good programmer, you should provide a shortcut to your users for almost every menu action performed on your application. As a suggestion, spend time with other people's applications, including commercial apps. Look at Microsoft Word for example. Many actions on that application have shortcuts even when the shortcut is not listed. It allows people who like shortcuts to do their job faster, it also anticipates the situations when the mouse is behaving badly.

if you look at the menu of most applications, one letter on every menu is underlined allowing the users to access the menu without using the mouse. That menu should first receive focus, this is done by pressing Alt or F10, then eventually the underlined letter of the menu that the user wants to access. For example, if you press Alt, then F now, the File menu will open. Get in the same good habit of accommodating your users.

a/ On the menu you are creating, click Format and hold the mouse. Then move the Format menu selected; as you are moving it, a short vertical line with double arrows is following and guiding you. Place it between View and Window.

b/ You should still have the Properties dialog on your screen. To apply one of the good habits, click the Font sub menu. In the Caption, add 3 periods to Font so that when you finish, it will read Font... The reason is that every time a menu is calling a dialog, it should display those periods (ellipsis) as an indication to the user. The three periods let the user that this particular menu will call a dialog box.
c/ The second good habit is to provide a mnemonic for each menu item so that the user can access the menu using the keyboard. The mnemonic is done by using the ampersand & before the letter you judge appropriate. Again, look at the menu of VC++. Good programmers make sure that there is no double underlined letter among those menu words. Only one F is underlined on the whole main menu, only one E, only one V, etc. Programmers tend to consider the first letter of each top menu. If you get in a situation where two words start with the same letter, consider using the 2nd letter.

On your menu, click Format. In the Properties dialog, change its Caption to F&ormat.

Also, change the Caption of Font to &Font... This time, you can use the F on Font because Font is a submenu of Format and when the Format menu is opened, the File menu will not be available.

The mnemonics can be used anywhere in your application, including dialog boxes, combo boxes, check boxes, radio buttons, etc. So, get in the habit of using them. The ones on the menu will be used if the menu has focus (Alt or F10). The others are available anytime.

This was a short scenario. Sometimes you will get in a situation where either you get confused because of so much menu to create, or too many items that need mnemonics (try to create a restaurant menu, or an employees database(?!?)). In any case you can ask Visual C++ to help you identify double mnemonics. Right-click on your menu and select Check Mnemonics.

d/ The job of the Status Bar is to display a message to the user about a menu item, like a small detail. Here is an example, on the main menu of Visual C++, click Projects -> Dependencies and look at the Status Bar. While the menu is still opened, move the mouse to Settings and look at the Status Bar. When you have finished, press Esc twice to dismiss the menu.

On the menu you are creating, click the Font... submenu. In the Properties dialog, click in the Prompt edit box and type: 
Changes the font features of the text

e/ A shortcut allows the user to work fast by easily applying or having access to various features of your application by pressing one key or a combination. For example, to open the Start menu of Microsoft Windows, you can press Ctrl + Esc, to open the System menu of any application, press Alt + Space, to save a document on most (if not all) Microsoft applications, press Ctrl + S., etc. Try to always provide shortcuts to your users.

People who use Microsoft Windows and Microsoft software products are already familiar with a lot of "universal" shortcuts such as Ctrl + C, Ctrl + V, Delete, etc. You can see some of these if you click File or Edit on the main menu. Those are shortcuts that are explicitly and readily available. Other shortcuts, though completely efficient, can also be made available. For example, did you know that the application you are using now already has some hidden shortcuts. To see it, build your application now. When it is running, since it is an MDI, you can close the current document without closing Notice. Press Ctrl + F4.

It is up to you to create shortcuts. But your users will know them only if you let them know. The easiest way to let users know about the shortcuts is by displaying them on the menu. For example Ctrl+N, Ctrl+C, etc are already displayed on the menu. To provide a shortcut, append \t and the shortcut combination.

On the menu you are creating, click the Edit menu. Click the Insert New Object... line. In the caption, add \tCtrl+I so that when you finish, it will read Insert &New Object...\tCtrl+I.

f/ To provide a shortcut, use the Accelerator object.

In the ResourceView, click the + sign of the Accelerator. Double-click the IDR_MAINFRAME Accelerator. In the list of accelerators on the right, click the last empty line. In the Accel Properties dialog, click the arrow on the ID combo box to display the list. Type ID_OLE_IN, when the ID_OLE_INSERT_NEW comes up, select it and press Tab. Type I in the Key box. Make sure that the Ctrl check box is checked in the Modifiers group. Press Enter.

Click the arrow of the ID combo box and type ID_FO, select ID_FORMAT_FONT from the list, and press Tab. In the Key box, type D. Make sure that the Ctrl check box is checked and press Enter.

I know that we didn't provide an explicit shortcut in the menu as \tCtrl+D. Microsoft did the same with Microsoft Word where you can call the Font dialog by pressing Ctrl + D, but Ctrl + D doesn't work in WordPad.


Home Copyright © 2000 FunctionX, Inc.