The Resource View of the MFC - Menu Editing
(Page 2 of 5 )
You can already see that Microsoft has included quite a few little tools into MFC that can enhance your programming speed dramatically. Resource manager has been included for even greater efficiency. With this handy tool we can customize our resources at a blazing fast speed. Resources can be categorized as Accelerator keys, the Dialog boxes, Icons, String Tables, Menus, Toolbars... and even a nice version of the info table.
The menu is at the base/top of each application window. You already see them everywhere, that is if you've spent at least 10 minutes in Windows. If a user wants to customize something, most of the time, the first place s/he expects this kind of option is the menu.
Considering this, your own application shouldn't be an exception. This way, any user can find his/her way in a familiar situation. Scaring away users by implementing something extremely unfamiliar or new isn't great. You may ask, how will we customize them? Well, the answer is quite simple; it's presented below.
All you need to do is open up the corresponding part of the resource tree and select IDR_MFC_exampleTYPE. That part is responsible for the mainframes menu. The initial customization is quite intuitive and can be done without any additional effort; typing the new menu string where you want a new menu is very straightforward. Additionally you may also insert separators by right clicking and selecting Add separator. For our application, let's make something like this.

At this time, the menus are useless, so we need to assign them some sort of functionality. Right click on the desired menu and select Add Event Handler...

Select the class that you want to assign and we are ready to go. In OnDataoptionsEnterdata, we can enter all the things we should be able to do and expect from pressing on the menu(s).
At this part, we'll learn how to add check boxes near a menu. It is quite a useful option and fits perfectly in our Use Blue Bk -> True section. To accomplish this, you need to repeat the above process once again, but this time choose the UPDATE_COMMAND_UI message type instead.
Add a _useBlue bool type variable that will indicate whether we draw with a blue background or not and set a start value of false. Add the COMMAND message so that we can change the value of the _useBlue; therefore, when you push the True menu we can signal to the application that a change has been made.
Each time the True menu is drawn, the OnUpdateUsebluebkTrue32775 function is called. So in it we indicate whether or not the check box has to be drawn. Add the following code in there. The result must be something like the screen shot below - a check box that disappears and appears upon selection.
void CMFC_exampleView::OnUsebluebkTrue()
{
_useBlue= (!_useBlue);
Invalidate();
}
void CMFC_exampleView::OnUpdateUsebluebkTrue32775(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(_useBlue);
}

A utility for Enter Data... will be integrated in the following page and there you are also going to find out how to create a Dialog Box. In the same way, you can implement radio boxes too.
Next: Dialog Boxes >>
More BrainDump Articles
More By Gabor Bernat