The Resource View of the MFC - Toolbar, Hot-Keys and Icons (Page 4 of 5 )
It is quite annoying to search the Data Options and Enter Data menu, so maybe we can speed up the process a little. The solution to our problem is the Toolbar. The Toolbar already contains a few icons, like Cut, Copy, Paste, and so forth. The only thing left to do is add our own. Select the IDR_MAINFRAME toolbar in the resource view and you can add another after the help icon (question mark). Just push down and after that, play a little with the colors and draw your fancy pictogram.
Assigning the icon with the Data Enter... menu is done by linking the icon to the menus ID. Search in Properties for what ID the Enter Data... menu has and add the same ID to the icon. If you've followed this tutorial, the corresponding ID is ID_DATAOPTION_ENTERDATA. You can see this in the attached screen shot below.

That's all we need to do. From now on, starting the program and pressing the icon is the same as searching for the option in the menu. Future improvements can be made by assigning a Hot-Key to the application. To do this, visit the Accelerator part of the Resource and add the desired Hot-Key for the corresponding ID. For the Dialog Bar, we'll add the Ctrl+F5 accelerator. Do the following; the interface is intuitive so you can figure out any other combination.


Finally, we can also advocate the addition of an accelerator key for aesthetics and other obvious reasons by modifying the caption of our menu in the Properties page to this: "&Enter Data..tCtrl + F5". The important part is adding the t in the text.
Modifying the icon of your application is simply drawing an image for the document type icon or the applications icon. Just search the Icon section in the menu and modify IDR_MAINFRAME for the application, while the applications document in our case is the IDR_MFC_exampleTYPE.
The String table can be used to display some tooltips or store some constant text that can be accessed from the table anytime. For example, if we want to add a little tooltip that will appear in the status bar, then as soon as we hover the mouse pointer over the Enter Data... menu, we assign the desired text to the menu's ID. For example, check out the entered data below in the attached screenshot.

You can also use the resource to add bitmaps, and by referring to the bitmap's ID, you can load it in your application and work with it just as with any other. The advantage of this is that you don't have to search for the path of the application because it will be included in the resource and can be accessed with just a couple of clicks.
One last concept we need to cover is the version tab, which contains information about the current version of the program, the authoring company, copyright details, contact information, and so forth. Basically, if you want to mark the application as yours and enter information about who made it, then this is the place to do it.
You may have already figured out that every resource has a unique ID assigned to it. We can refer to the resource anywhere in our application by including "Resource.h" in the implementation file (this is where the IDs are defined) and using their IDs as identifiers. Click the button below to download the program that we made; feel free to experiment with it. You should find it especially useful if you were struggling.

Next: Epilogue >>
More BrainDump Articles
More By Gabor Bernat