How Do I? | - by Eric Slaats |
Hi, welcome to the next lesson on PM programming. In this column simple Presentation Manager programming problems and philosophies will be discussed. This column is aimed at people who are interested in PM programming or are simply curious what makes PM programs tick. To understand this column a little programming experience (preferably in C++) is recommended.
Last month we took a small peek at resources. We found that resources can make life a lot easier. For example, we don't have to program menus, we simply define them and let the PM do the rest. Before we delve further into the possibilities of other resources, we will explore the resource MENU some more.
Menu's are a very important part of your application. They must be treated with some respect and usually require some thinking before they are created. Most of you will have experience with mastodon programs like WordPerfect or Microsoft Word. These programs have enormous menu trees and it's often very hard (if not impossible) to find what you're looking for. The menus of a lot of programs are overfull, illogical, devoid of accelerator hints, have no key shortcuts, etc.
In this months article we will take a look at techniques that will make menus more attractive and easier to use. But before we do that, let's find out something about the CUA guidelines.
CUA stands for Common User Access. CUA is a set of guidelines that are a piece of IBM's SAA (System Application Architecture). These guidelines were introduced in 1987 and have seen a number of changes through the years. New controls are invented constantly and the way they should look is added to the CUA guidelines. Basically, CUA is an attempt to make user interfaces look coherent in such a way that users will find what they have come to expect.
CUA also describes menu appearances. An example of this is that CUA says that a menu that will invoke a dialog should be followed by three dots (...). In the samples handled in this article we will try to follow the CUA guidelines.
Back to menus. What do we have available to make menus? Unfortunately not everything can be handled with resources, but the amount of code needed will be kept to an absolute minimum. Remember, don't do anything the system can do for you. In addition to what's handled in last month's column, we will take a look at the following:
Mnemonics are very easy to create, just place a ~ (tilde) before the letter of the menu item you want to be the mnemonic key. It's a good practice to implement mnemonics for all your menu items.
Note: mnemonics can also be used in dialogs for buttons, etc.
MENUITEM SEPARATOR - a separator is usually used to draw a line between sets of menu items that form a functional cluster. For example, in an edit submenu the items clear, copy, cut and paste are separated from other menu items by a separator line. In the separators submenu these lines can be observed. Such a line can be placed by creating a menu item with the name "separator".
MIS_BUTTONSEPARATOR - a separator that most programs use to give the Help menu item a place on the right side of the menu with a small line in front of it. The Help submenu in sample4.exe is placed this way. CUA says the menus must be done this way, but personally I think it's a matter of taste (Smalled doesn't have this).
MIS_BUTTONSEPARATOR is a menu-item-style component. (That is why it begins with a MIS_ prefix.) The SEPARATOR is a real menu item, although one that can't be selected. MIS_ items can only be applied to existing menu items.
MIS_BREAKSEPARATOR - breaks a submenu before the item to which it is applied. This way more columns (or menu lines) can be created. The BREAKSEPARATOR draws a line between the columns. It's also possible to use MIS_BREAK. With this option the line won't be drawn. In the separators submenu in Sample4, both styles are displayed.
Bitmaps can also be treated as resources. For this month's sample I created two bitmaps with the standard icon editor and included them in the RC file. To do this the following lines were added:
// Bitmap identifiers BITMAP 1001 "FILEBUT.BMP" BITMAP 1002 "DIRBUT.BMP"With these lines inserted, the bitmaps can be handled as resources. To place these bitmaps on a menu item the first thing that has to be done is create a menu item with the bitmap style. Two of the menu items in the Bitmaps submenu are created like this. The text-items are added to show that text and bitmaps can be combined. Also you can observe that a bitmapped menu is sized according to the bitmap it contains.
SUBMENU "~Bitmaps", IDM_MENU BEGIN MENUITEM "Text", IDM_ITEM MENUITEM "#1001", IDM_ITEM, MIS_BITMAP MENUITEM "#1002", IDM_ITEM, MIS_BITMAP, MIA_FRAMED MENUITEM "Text", IDM_ITEM ENDIn the sample you can see that the text for the bitmapped menu items contain a # sign followed by the ID of the bitmap placed on it. The # is a directive for the resource compiler that tells it which bitmap to use.
The second bitmapped item also has an attribute attached to it. This is the MIA_FRAMED attribute. If the bitmap submenu is examined, the effect of this attribute can be observed, it draws a small line around the menu item. This gives a nice visual effect that is especially useful with bitmapped items.
To left align a piece of text, we add a \t in the declaration. (You may recognize this as the escape sequence for a Tab in the C/C++ printf() statement.) To right align a column, add a \a in the declaration.
SUBMENU "~Columns", IDM_MENU BEGIN MENUITEM "1 \t****", IDM_ITEM MENUITEM "22 \t***", IDM_ITEM MENUITEM "333 \t**", IDM_ITEM MENUITEM "4444 \t*", IDM_ITEM MENUITEM "5 \a****", IDM_ITEM, MIS_BREAKSEPARATOR MENUITEM "66 \a***", IDM_ITEM MENUITEM "777 \a**", IDM_ITEM MENUITEM "8888 \a*", IDM_ITEM END
What do we have to do to create a cascade menu? Well, nothing. If we create a submenu in a submenu the resource compiler will automatically add the little arrow and so provide us with the visual clue that another submenu exists.
That's all for now. Next month we'll delve further into the possibilities of menus. A little programming will be added and we will see that a lot more can be done with menu resources.
[Our Sponsor: MR/2 ICE Internet Email Client - Delivering the Email features of the future, today.]
Copyright © 1997 - Falcon Networking
This page is maintained by Falcon Networking. We welcome your suggestions.