23.9 Adjusting the program appearance

The caption bar and the About dialog

To start with, the caption bar for a project like Pop will say something like:

Pop “ [Pop1]

The second name is the name of the View window that currently has the focus. If the child window is maximized, the name is in square brackets; otherwise it's not, and will say something like:

Pop “ Pop1

The ' Pop1 ' is a program-generated name for the file (the 'document') that you currently have open . If you use the File Open or the File Save As... commands, this name will change to reflect your current choice of a file name. (At present, 'opening' or 'saving' a file will have no real effect except for changing the name in the caption bar. We'll show you how to properly save and open files later, when we'll have some data worth saving.)

The default first phrase, ' Pop ,' is the name of your project file. Particularly when you are working on a series of builds, as in a software project, you want this caption to have more information than your project file name, which you usually pick to be very short and generic. The easiest way to use the Pop Framework is just to leave the project name as it is, so your project file will still probably be Pop, no matter what your executable is. (It is possible to change the project name, but it's a little bit of trouble.)

You generally want your caption bar to also include your name and the date of the build. So if, for instance, you were calling your program, say, 'Skull Farmer,' you'd change the caption bar to say something like this, indicating that the program is showing the file number 1 opened by Version 7 of your Skull Farmer program.

Skull Farmer, Version 7, Your Name Here, July 5, 2010. “ [Pop1]

The way to change the caption is to go to the Resource sheet of your Workspace pane in your compiler. Click on Pop Resources to show the resource categories and click on String Table to make a window open up listing your string resources. The first string will have the identifier IDR_MAINFRAME . This is the string that appears as your program name in the caption. Right-click on the text of this string to get a popup context menu, select Properties on this popup, and then you can edit the string to include the version number, your name, and the date.

It's also a good idea to put some information into the About dialog box. You can do this from the Resource view by clicking on Dialogs and then clicking on IDD_ABOUT . Right-click on the text area to get a context menu and select Properties... to get a dialog where you can change the text to have your name.

The program icons

It's a nice idea to use the Resource Editor to change the icons used by the your programs. Although this isn't immediately obvious, your program uses four icons, and to fully customize your program you need to change them all. The so-called IDR_MAINFRAME icon comes in two different sizes, and the IDR_POPTYPE icon comes in two sizes as well.

Under the Icons listing on the Resource sheet of the Workspace window, you'll find IDR_MAINFRAME and IDR_POPTYPE . IDR_MAINFRAME controls the icon that appears next to your *.exe in Windows Explorer and in the About dialog box; by default it shows three blocks with the letters MFC. You can change this icon in the Resource Editor, but at first you won't think it worked “ because you'll still see the three blocks with MFC in your main menu bar. Why is that? Well, each icon is stored to actually hold images at two different resolutions . In the Resource Editor you'll find a Device dropdown with two choices: Standard (32 x 32) and Small (16 x 16) . And you need to change the Small one of IDR_MAINFRAME to change what you see in the caption bar when the document window is maximized.

With IDR_POPTYPE , the Standard version will appear next to Pop documents if we eventually save any, while the Small version will appear in the menu bar when the document window is maximized.

The IDR_MAINFRAME and IDR_POPTYPE icons are saved in the current \res file as Pop.ico and PopDoc.ico respectively. Sometimes when you change the icons, the compiler seems not to pick up on the changes. This is particularly likely to happen if you drag new icons into the \res directory and simply assign them the names Pop.ico and PopDoc.ico . One way to 'jolt' the compiler and get it to notice that things have changed is to remove all icons from the \res directory, try and open the workspace file, and let the compiler complain that it can't find any icons. If you then put some icon files back in, the compiler will now use them.

Tweaking the File dialog

This is something you should do first of all when you start trying to serialize your program's documents. What we do here is find a way to give a distinctive file-name extension to our serialization files. Detailed discussion of the serialization process itself appears in Chapter 29 Serialization.

The reason it's a good thing to fix the File dialog before starting to implement serialization is that when you're testing out your code with repeated saves and opens, it's a lot easier to find the files you're testing if they have a distinctive kind of name.

Table 23.6. Where to edit the MFC document string to change your parameter file type.

Feuer's name

Default for Pop Project




This is the text for the title bar by an SDI app, but an MDI app uses the IDR_MAINFRAME string instead



The default document caption, used with a number after it



Document type, used with the File New command if your app has several types of docs



A descriptive phrase shown by the File Open and File Save to filter for the app's types of documents



The default file extension used for your file type



Systemwide identifier used for the file type in the registry if the app registers itself


Pop Document

The user -readable name used for your type of file in Windows Explorer if the app is registered

If you use the Resource Editor to look inside the string table resource for your project, you'll find the second line has the label IDR_POPTYPE . By default, AppWizard sets it to the following string.

 \nPop\nPop\n\n\nPop.Document\nPop Document 

This kind of object is a kind of 'string of strings' because each of the \n symbols is a new-line symbol. Really we have seven substrings here, although by default three of them (the very first one, the fourth and the fifth) are empty strings of the form \n .

A good explanation for the Document String is in Alan Feuer's MFC Programming (Addison-Wesley, 1997), p. 218, where Feuer explains that the seven strings can be named like this and explained as in Table 23.6, where we've shaded the two lines that are important for us here.


Thus, when building, say, Pop21, you might want to use the extension .p21 for the files, and you might want to have the File Open and File Save dialogs refer to these files as having the type 'Pop 21 File.' To make this happen, all we would need to do is to use the Resource Editor to make two changes to the IDR_POPTYPE document string, so that it looks like this.

 \nPop\nPop\nPop 21 File\n.p21\nPop.Document\nPop Document 

Software Engineering and Computer Games
Software Engineering and Computer Games
Year: 2002
Pages: 272

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net