16. Object-oriented Programming Foundations

Chapter 20 - Concepts and Tools for Windows Applications

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

Visual C++ Windows Development Tools
The Visual C++ compiler contains several resource editors. The individual editors are available by selecting Insert | Resource from the compiler’s main menu. These editors allow for the quick definition of icons, cursors, and bitmaps. They also provide a convenient method for creating your own unique fonts and make it easy to create dialog-box descriptions for data entry.
Resources have the capability of turning ordinary Windows applications into truly exciting graphical presentations. When you develop icons, cursors, menus, bitmaps, and more for your application, the graphical flare makes your programs presentation quality in appearance. Resource files also let you add user-interactive components to your program such as menus, keyboard accelerators, and dialog boxes.
Graphics objects such as icons, cursors, carets, message boxes, dialog boxes, fonts, bitmaps, pens, and brushes are all examples of resources. A resource represents data that is included in an application’s executable file. Technically speaking, however, it does not reside in a program’s normal data segment. When Windows loads a program into memory for execution, it usually leaves all of the resources on the disk. Consider, as an example, when the user first requests to see an application’s About box. Before Windows can display the About box, it must first access the disk to copy this information from the program’s executable file into memory.
The resource compiler, RC.EXE, is a compiler for Windows resources. Many times, a Windows application will use its own resources, such as dialog boxes, menus, and icons. Each one of these resources must be predefined in a file called a resource file or resource script file. These files are created with the resource editors previously mentioned. Resource script files can be compiled into resource files by the resource compiler. This information is then added to the application’s final executable file. This method allows Windows to load and use the resources from the executable file.
The use of resources and additional compilers adds an extra layer of complexity to application development, but one that is easily incorporated with the project utility.
Project Files
Project files provide an efficient means of overseeing the compilation of resources and program code as well as keeping the executable version of an application up to date. They accomplish their incremental operation by keeping track of the dates and times of their source files.
Project files include information about the compile and link process for the particular program. Programmers often have the choice of changing libraries, hardware platforms, software platforms, etc. Project files are created within the integrated C and C++ editing environment. In many cases, the default project file setup can be used with just minor adjustments for program titles and a file list to include in the build operation.
Project files also support incremental compiles and links. For example, consider a Windows application that simulates the flight of an arrow. During the development process, you decide to create your own unique cursor instead of pointing with the standard arrow provided by Windows. You create a cursor that looks like an apple with an arrow through it. When the application is recompiled incrementally, the program only really needs to accommodate the changes in the cursor resource file, APPLE.CUR. The project utility will ensure that only the information about the new cursor is updated during recompilation, speeding up the overall operation.
Resources
Customizing a Windows application with your own icons, pointers, and bitmaps is easy when you use the resource editors provided with the C++ compiler. These editors give you a complete environment in which to develop graphical resources. The editors will also help you create menus and dialog boxes—the basic means of data entry in Windows. In this section, you learn how to use these editors to create icons, cursors, menus, and dialog boxes. The editors can also help you manipulate individual bitmaps, keyboard accelerators, and strings.
Resource Editors
Each editor is included within the Visual C++ environment and is an integral part of the compiler. As such, each editor is a completely integrated resource development environment designed to run under Windows. You can start each editor by first selecting the Insert | Resource menu options.
Icons, Cursors, and Bitmaps
This section describes the general operation of three editors. A specific editor is capable of producing icons, cursors, or bitmaps. Although each is a separate editor, they share many common features. As an example of the use of these image editors, a custom icon and cursor will be created for an application in the next chapter. Icons and cursors are really both small bitmaps. The resource editors for designing icons and cursors allow you to create device-independent bitmap images. The icons and cursors created with these editors are functionally device independent with respect to resolution.
This image-file format allows for the tailoring of a bitmap that has a consistent look on each particular display resolution. For example, one icon might consist of four definitions (called DIBs): one designed for monochrome displays, one for CGAs, one for EGAs, and one for VGAs. Whenever the application displays the icon, it simply refers to it by name; Windows then automatically selects the icon image best suited to the current display. Figure 20-8 shows the Editor window during the construction of a custom icon.
Figure 20-8: A custom icon is created with the resource editor
Initially, a color palette appears at the bottom of the editor for selecting the drawing color. Associated with this palette is a color box that shows the currently selected value. You can also create custom colors. A group of editing tools is also visible at the extreme right of the window.
A large editing area is provided for drawing the icons, cursors, or bitmaps. The area is initially divided into smaller cells with a 32 32 grid. The editor also provides a small View window to allow you to observe the graphics in true size.
Designing a Custom Icon and Cursor
Creating your first icon or cursor is simple. First, click on the compiler’s Insert menu and select Resource. Now select the proper resource type (Bitmap, Icon, Cursor) from the resources listed. This action clears the editing area if any previous design is present, and gives you a clean canvas.
After selecting the icon or cursor resource, you will need to pick a drawing tool from the toolbox or use the default drawing pen.
The editor can provide a broad spectrum of painting colors for icons and a selection of dithered colors for cursors. Click the color choice from the palette of colors shown. Now it is possible to draw the icon, cursor, or bitmap to your program’s specification. You can also create custom colors. Be sure to save your final results by selecting the File menu and either the Save or Save As option.
Figure 20-9 shows the editor window with a completed cursor design. When looking at the completed icon or cursor designs, you will note that there are actually two renditions of the design. The larger one, within the editing area, allows you to easily visualize an image. The smaller version, to the left, represents the actual size of the design, as it will appear in the application’s window.
Figure 20-9: The resource editor during the creation of a unique cursor
It takes a great deal of patience and practice to create a meaningful icon, cursor, or bitmap. This process often requires several trial-and-error attempts. Whenever you come up with a design that looks good, stop and save a copy of it. It is too easy to get your design to a point where you really like it and make one additional change, only to ruin hours of work.
The first time you select the Save option from the File menu, the editor prompts you for a filename. If you are creating an icon, the file system will automatically append an .ICO file extension. The .CUR file extension is used for cursors. (Note that the file extension must be .ICO or .CUR, respectively.) If you are creating several possible designs, make certain you choose the Save As... option, not Save. Save overwrites your original file, but Save As... allows you to create multiple copies.
When you are creating cursors, you can select an optional hotspot. The Hotspot button is located just above the drawing palette. The cursor hotspot is a point that will be used to return the current screen coordinates during the application’s use. The hotspot on the pie wedge cursor is located at the tip of the pie wedge.
Once you have selected the Hotspot button, a very small set of crosshairs appears in the drawing box. Simply place the crosshairs on the pixel you want to select as the hotspot and click the mouse. The coordinates of the selected hotspot will be added to the display box’s list of statistics. Only one hotspot per cursor is allowed.
Designing Menus
Menus are one of Windows’ most important tools for creating interactive programs. Menus form the gateway for easy, consistent interfacing across applications. In their simplest form, menus allow the user to point and click selections that have been predefined. These selections include screen color choices, sizing options, and file operations. More advanced menu options allow the user to select dialog boxes from the menu list.
Dialog boxes permit data entry from the keyboard. They allow the user to enter string, integer, and even real-number information for applications. However, before you can get to a dialog box, you typically must pass through a menu.
The menu created in this section is also used in the graphics application developed in the next chapter.
Menu Mechanics
The following sections describe what a menu is, what it looks like, how it is created, and the various menu options available to the programmer. Menus are very easy to create and implement in a program.
WHAT IS A MENU?
A menu is a list of items or names that represent options that a user can take. In some cases, the list of items in a menu can even be bitmap images. The user can select an option by using the mouse, the keyboard, or a hot key. Windows, in turn, responds by sending a message to the application stating which command was selected.
CREATING A MENU
The resource editor lets you select a menu resource. The menu will then be designed in the resource editor. An alternative technique is to use the compiler’s text editor to specify a menu resource.
The resource editor is capable of creating or reading menu descriptions contained in resource script files (.RC) or compiled resource files (.RES). Resource script files are simply uncompiled text files. If a header file is available describing constants used in a menu’s description, these can be added at the start of the menu’s description. For example, the constant IDM_ABOUT might be identified with 40 in a header file.
Figure 20-10 shows a menu (PieMenu) being developed in the resource editor.
Figure 20-10: The resource editor is used to create a new menu
Different styles and attributes for application menus can be included in this file. These styles and attributes include checkmarks to indicate the status of an item or define styles for an item’s text (normal or grayed) and separator lines to divide menus (menu bar breaks), align menu items in column format, and assign a help attribute to a menu item.
MENUS AND THE RESOURCE COMPILER
By following a set of simple rules, Windows will draw and manage menus for you. In so doing, Windows will produce consistent menus from one application to another. The resource compiler will compile menu resource information. The compiled file, a file with a .RES file extension, will be combined with your application at link time. At this time, the compiler and linker will create the final executable file (.EXE).
The structure of a simple menu is quite easy to understand. Here is a resource script file:
PIEMENU MENU DISCARDABLE
BEGIN
 POPUP “Pie_Chart_Data”
 BEGIN
   MENUITEM “About...”, IDM_ABOUT
   MENUITEM “Input...”, IDM_INPUT
   MENUITEM “Exit”,     IDM_EXIT
 END
END
By studying this listing, you can identify a number of additional menu keywords such as MENU, POPUP, and MENUITEM. You can use brackets ({ }) instead of the keywords begin and end. It is also easy to identify the menu items that will appear in this menu: About Box..., Data Entry..., and Exit. The three dots following a menu selection indicate a dialog box to the user.
MENU KEYWORDS AND OPTIONS
The name of this program’s menu definition is PIEMENU. The menu definition name is followed by the keyword MENU. This particular example describes the pop-up menu Pie_Chart_Data, which will appear on the menu bar. Pop-up menus are arranged from left to right on the menu bar. If a large number of pop-up items are used, an additional bar is provided automatically. Only one pop-up menu can be displayed at a time.
You can use an ampersand to produce an underscore under the character that follows the ampersand in the selection list. The ampersand allows the menu item to be selected from the keyboard. The simple menu in the example does not take advantage of this feature, but if the “A” in the About Box... choice had been preceded with an ampersand, that selection could have been made with a key combination of alt-a. With the example menu, the item can be selected by positioning the mouse pointer on the item and clicking the left button. When a pop-up menu is selected, Windows pops the menu to the screen immediately under the selected item on the menu bar. Each MENUITEM describes one menu item or name, for example, “Data Entry....”
Identification numbers or constants from a header file appear to the right of the menu items. If numbers are present, they can be replaced with values identified in header files—for example, IDM_ABOUT 40, IDM_INPUT 50, and IDM_EXIT 70. IDM stands for the identification number of a menu item. This form of ID has become very popular, but is not required. What is important, however, is that each menu item have a unique identification associated with it.
KEYBOARD ACCELERATORS
Keyboard accelerators are most often used by menu designers as a sort of “fast-key” combination for selecting menu items. For example, a menu may have 12 color items for selecting a background color. The user can point and click the menu for each color in the normal fashion or, with a keyboard accelerator, simply hit a special key combination. If a keyboard accelerator is used, the function keys (f1 to f12), for example, could be used for color selection without the menu popping up at all.
Dialog Box Data Entry
You have already learned that menus are considered as a means of simple data entry. This section investigates a more significant means of data entry—the dialog box. While data can be entered directly into the application’s client area, dialog boxes are the preferred entry form for maintaining consistency across Windows programs.
Dialog boxes allow the user to check items in a window list, set buttons for various choices, directly enter strings and integers from the keyboard, and indirectly enter real numbers (floats). A special form of control can also be used in a dialog box. Combo boxes allow a combination of a single-line edit field and list boxes. The dialog box is the programmer’s key to serious data entry in Windows programs. The dialog box is also the programmer’s secret for ease of programming since Windows handles all necessary program overhead.
Dialog boxes can be called when selected as a choice from a menu and appear as a pop-up window to the user. To distinguish a dialog box choice from ordinary selections in a menu, three dots (an ellipsis) follow the dialog option name. In the previous section, the About Box... and Data Entry... menu items referred to dialog box selections. Figure 20-11 shows a completed dialog box taken from an example that is developed in the next chapter.
Figure 20-11: A completed dialog box for data entry
Here is the resource script file for this dialog box:
PIEDLGBOX DIALOG DISCARDABLE  93, 37, 195, 159
STYLE DS_MODALFRAME|WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU
CAPTION “Pie Chart Data”
FONT 8, “MS Sans Serif”
BEGIN
 GROUPBOX “Chart Title:”,100,5,3,182,30,WS_TABSTOP
 GROUPBOX “Pie Wedge Sizes:”,101,3,34,187,95,
          WS_TABSTOP
 LTEXT “Title: ”,-1,10,21,30,8
 EDITTEXT DM_TITLE,40,18,140,12
 LTEXT “Wedge #1: ”,-1,10,50,40,8,NOT WS_GROUP
 LTEXT “Wedge #2: ”,-1,10,65,40,8,NOT WS_GROUP
 LTEXT “Wedge #3: ”,-1,10,80,40,8,NOT WS_GROUP
 LTEXT “Wedge #4: ”,-1,10,95,40,8,NOT WS_GROUP
 LTEXT “Wedge #5: ”,-1,10,110,40,8,NOT WS_GROUP
 LTEXT “Wedge #6: ”,-1,106,50,40,8,NOT WS_GROUP
 LTEXT “Wedge #7: ”,-1,106,65,40,8,NOT WS_GROUP
 LTEXT “Wedge #8: ”,-1,106,80,40,8,NOT WS_GROUP
 LTEXT “Wedge #9: ”,-1,106,95,40,8,NOT WS_GROUP
 LTEXT “Wedge #10:”,-1,102,110,45,8,NOT WS_GROUP
 EDITTEXT DM_P1,55,45,30,12
 EDITTEXT DM_P2,55,60,30,12
 EDITTEXT DM_P3,55,75,30,12
 EDITTEXT DM_P4,55,90,30,12
 EDITTEXT DM_P5,55,105,30,12
 EDITTEXT DM_P6,150,44,30,12
 EDITTEXT DM_P7,150,61,30,12
 EDITTEXT DM_P8,150,76,30,12
 EDITTEXT DM_P9,149,91,30,12
 EDITTEXT DM_P10,149,106,30,12
 PUSHBUTTON “OK”,IDOK,39,135,24,14
 PUSHBUTTON “Cancel”,IDCANCEL,122,136,34,14
END
The specifications that make up a dialog box are typically produced with the resource editor. The resource editor is designed to read and save dialog resource files in the text (.RC) and compiled format (.RES). Text files make it easy to combine several menu and dialog box specifications in one file.
DIALOG BOX CONCEPTS
Dialog boxes are actually “child” windows that pop up
when selected from the user’s menu. When various dialog box buttons, checkboxes, and so on are selected, Windows provides the means necessary for processing the message information.
Dialog boxes can be produced in two basic styles—modal and modeless. Modal dialog boxes are the most popular, and are used for the example developed in the next chapter. When a modal dialog box is created, no other options within the current program will be available until the user ends the dialog box by clicking an OK or Cancel button. The OK button will process any new information selected by the user, while the Cancel button will return the user to the original window without processing new information. Windows expects the ID values for these push buttons to be 1 and 2, respectively.
Modeless dialog boxes are more closely related to ordinary windows. A pop-up window can be created from a parent window, and the user can switch back and forth between the two. The same thing is permitted with a modeless dialog box. Modeless dialog boxes are preferred when a certain option must remain on the screen, such as a color select dialog box.
Dialog Box Design
There are two ways to enter the specifications for a dialog box. If you are entering information from a magazine or book listing, it will be easiest for you to use the compiler’s text editor and simply copy the given menu and dialog box specifications into a resource script file, a file with an .RC file extension. When the resource script file is compiled, the resource compiler will create a file with an .RES file extension. If you are creating a new dialog box from scratch for your project, you should use the appropriate resource editor. The next few sections discuss the fundamentals of using the resource editor to create and modify a dialog box. Microsoft’s online help utility will provide additional information for more advanced features and editing.
Reconsider the dialog box resource script file, shown earlier in this chapter, to convince yourself of the need for a resource editor for dialog boxes. The resource editor allows you to design the dialog box in a graphical environment.
Examine the dialog box resource script file shown earlier. Ask yourself the following questions. Where do all those terms come from? What do all those numbers mean? How could I figure all of this out without the resource editor? You would have to create, size, and place dialog boxes and their associated controls on the screen experimentally. The resource editor, on the other hand, will do all this for you automatically. Except for being able to make the claim that you created a dialog box without the resource editor at least once in your life, there is no reason for designing dialog boxes without the graphical environment of the editor.
Dialog Box Mechanics
If your dialog box information is entered in ASCII form from a book or magazine article, it must be compiled. This involves the use of the resource compiler. The resource compiler works in conjunction with the resource editor. On the other hand, if you are creating a new dialog box for a project from scratch, use the resource editor by selecting the Insert | Resource menu from the compiler’s main menu bar. Then, select the Dialog Box option. A screen similar to the one in Figure 20-12 should appear.
Figure 20-12: The Resource editor’s initial dialog box form
The screen now contains the initial outline for the new dialog box. This initial dialog box can be moved about the screen and sized to fit your needs. The screen in Figure 20-13 shows the initial dialog box moved and sized with several controls in place.
Figure 20-13: A dialog box under construction in the resource editor
PLACING TOOLBOX CONTROLS
By far the most important aspect of using the resource editor when designing dialog boxes is an understanding of the various controls that are provided for the user in the toolbox. Figure 20-14 shows the toolbox used by the resource editor when designing dialog boxes.
Figure 20-14: The resource editor’s toolbox for dialog boxes
Here is a brief explanation of the toolbox controls.
  The Static Text control allows the insertion of labels and strings within the dialog box. These can be used, for example, to label an edit box.  Select this control using the toolbox icon with the upper and lower case characters.
  The Group Box control creates a rectangular outline within a dialog box to enclose a group of controls that are to be used together. A group box contains a label on its upper-left edge. Select this control using the toolbox icon with the rectangular outline with text on the upper edge.
  The Check Box control creates a small square box, called a check box, with a label to its right. Check boxes are usually marked or checked by clicking with the mouse, but they can also be selected with the keyboard. Several check boxes usually appear together in a dialog box; they allow the user to check one or more features at the same time. Select this control using the toolbox icon with the “x” or check mark located in a small rectangular region.
  The Combo Box control is made up of two elements. It is a combination of a single-line edit field (also called a Static Text control) and a List Box control. With a combo box, the user has the ability to enter something into the edit box or scroll through the list box looking for an appropriate selection. Windows provides several styles of combo boxes. Select this control using the toolbox icon with three rectangular areas. This control is located under the Check
Box control.
  The Horizontal Scroll Bar controls allow horizontal scroll bars to be created for the dialog box. These are usually used in conjunction with another window or control that contains text or graphics information. Select this control using the toolbox icon with the left and right directional arrows.
  The Spin control creates two small rectangular areas, one on top of the other. The top area has an upward-pointing arrow and the bottom a downward- pointing arrow. This control functions like the thumb-wheel control on the new Microsoft mouse, allowing you to click selections up or down. Select this control using the toolbox icon with the two pyramid shapes (one upright and one upside down).
  The Slider control initially creates a horizontal slider button and track. The control can be changed to a vertical Slider control by changing the property of the control once it is placed in the dialog box. Slider controls are used frequently in place of scroll bars when simpler actions are required. Select this control using the toolbox icon with the Slider button and horizontal track.
  The List control contains a rectangular area for a list of items (these may be small iconic images) and a vertical scroll bar. This control is similar to the List Box control, but contains the vertical scroll bar. Select this control using the toolbox icon with the nine small images within the rectangular area.
  The Tab control is used when a dialog box is to contain a large amount of information. Instead of creating a complicated dialog box with one screen, the Tab control allows the user to flip to different pages within the dialog box. Each page then contains just a portion of the overall information. Select this control using the toolbox icon with the small tab folder.
  The Rich Edit control allows the user to enter and edit multiple lines of text. Formatting can be applied as well as embedded OLE objects. Select this control using the toolbox icon with underlined “ab” characters.
  The Picture control allows a rectangular area to be placed in the dialog box where a bitmapped image can be placed. Select this control using the toolbox icon with the small picture.
  The Edit Box control creates a small interactive rectangle on the screen in which the user can enter string information. The edit box can be sized to accept short or long strings. This string information can be processed directly as character or numeric integer data and indirectly as real-number data in the program. The edit box is the most important control for data entry. Select this control using the toolbox icon with the lowercase “ab” characters.
  The Button control, is a small, slightly rounded, rectangular button that can be sized. The button contains a label within it. Buttons are used for making an immediate choice such as accepting or canceling the dialog box selections made. Select this control using the toolbox icon with rounded rectangular shape.
  The Radio Button control creates a small circle, called a radio button, with a label to its right. Radio buttons, like checkboxes, typically appear in groups. However, unlike checkboxes, only one radio button can be selected at a time in any particular group. Select this control using the toolbox icon with the small bull’s-eye.
  The List Box control creates a rectangular outline with a vertical scroll bar. List boxes are useful when scrolling is needed to allow the user to select a file from a long directory listing. Select this control using the toolbox icon with the rectangular area and upward- and downward-facing arrows.
  The Vertical Scroll Bar control allows vertical scroll bars to be created for the dialog box. These are usually used in conjunction with another window or control that contains text or graphics information. Select this control using the toolbox icon with the upward- and downward-facing arrows.
  The Progress control produces a small bar that an application can use to indicate the progress of an operation. The progress bar is filled from left to right. Select this control using the toolbox icon with the small progress bar image.
  The Hot Key control enables the creation of a hot key. A hot key is a key or
key combination that allows the quick selection of items such as menu selections and so on. Select this control using the toolbox icon with the
button and finger combination.
  The Tree control displays a list of data in a tree structure. This control is helpful when you wish to convey to the user a hierarchical structure. Select this control using the toolbox icon with the small tree structure image
  The Animate control supports the displays of an AVI clip (audio video interleaved). The clip is created as a short series of bitmap frames. This is the technique used for making animated cursors. Select this control using the toolbox icon with the two file frames.
  The Custom Control control allows the use of existing custom or user controls. This technique has been replaced by the use of ActiveX controls and is included to be backward compliant. Developers should elect to use ActiveX controls. Select this control using the toolbox icon with the image of a person.
You can place controls in the current dialog box outline by selecting the appropriate control from the toolbox, positioning the mouse pointer in the dialog box, and clicking the mouse button. If the placement is not where you desired, you can use the mouse for repositioning. It is also possible to size the controls once they are placed.
Creating a Dialog Box
In this section, a simple About dialog box is created. About dialog boxes are used to identify the project and developers, give a copyright date, and so on. They usually contain only one push button—OK. They are the easiest dialog boxes to design. Figure 20-15 shows a sized and positioned dialog box outline awaiting the final placement of the Text and Button controls.
Figure 20-15: A dialog box waiting the final placement of controls
In this dialog box example, only two types of controls will be used—the Text and Button controls. You can use the mouse to place, size, and position the Text Box control in the dialog window. Clicking the mouse within the box after positioning it will allow editing of the actual text string. Figure 20-16 shows several controls where the text has been edited.
Figure 20-16: A control’s text is changed in this version
The string to be printed is entered in the Text window, where the word “Static” now appears. The ID value is automatically supplied. Now position the OK push button in the About box. To delete an existing control, such as “Cancel,” click on the control and hit the del key. Clicking the mouse within the button allows you to enter the text for the button. In this case, it will be “OK.” Figure 20-17 shows the placement of the push button and the final dialog box.
Figure 20-17: The completed About dialog box
You can then save the dialog box information by selecting the Save option from the File menu. Remember that the resource editor will save this file in the text (.RC) or compiled resource form (.RES). Using the resource editor to create dialog boxes is a skill learned with practice. Large dialog boxes, utilizing many controls, will initially take hours to design. Again, use the detailed information contained in the Help menu or your Microsoft user’s manuals. Start with simple dialog boxes and work toward more complicated designs.
EXAMINING THE RESOURCE SCRIPT
You can examine the script file information once the resource is saved as an .RC file. Use any ASCII text editor to see the About
box description.
ABOUTDLGBOX DIALOG DISCARDABLE  50,300,180,84
STYLE DS_MODALFRAME|WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU
CAPTION “About”
FONT 8, “MS Sans Serif”
BEGIN
 CTEXT “Microsoft C Pie Chart Program”,-1,3,29,176,10
 CTEXT “by William H. Murray and Chris H. Pappas”,-1,3,16,
        176,10
 PUSHBUTTON “OK”,IDOK,74,51,32,14
END
The name of this dialog box is ABOUTDLGBOX. The editor has affixed various segment values along with size specifications for the box. The various style options further identify the dialog box as one that has a modal frame and is a pop-up type. Three controls are listed.
The first and second control specifications are for static text. The remaining specifications establish the text position and type.
The third control specifies an OK push button. The text within the first set of double quotes specifies what will appear within the push button. The labels for the ID values for the push button are a system default.
Remember that it is not necessary to view this information at all. The resource editor will convert the graphics dialog box you see on the screen directly into a compiled resource file (.RES). The only time you will need this information is when you are entering dialog box specifications from a book or magazine.
The About dialog box we just created is used in the next chapter.
Resource Statements
You can also use resource script files for combining menu and dialog resources in one file.
Defining additional resources for an application is as simple as naming the resource ID followed by a resource compiler keyword and then the actual filename. Suppose you’ve created a resource script file called MYRES.RC:
myicon ICON myicon.ico
mycursor CURSOR mycursor.cur
mybitmap BITMAP mybitmap.bmp
Remember that MYRES.RC is a resource script or text file that defines three new resources. The names of the three resources are myicon, mycursor, and mybitmap. Icon, cursor, and bitmap are reserved keywords defining the type of the resource. These are followed by the actual filenames containing the resource information; for example: MYICON.ICO, MYCURSOR.CUR, and MYBITMAP.BMP.
There are five additional options that can be included with each single-line statement. These options follow the resource-type keyword and include preload, loadoncall, fixed, moveable, and discardable. The first two options define load options; the latter define memory options. For example:
resourceID resource-type [[load-option]] [[memory-option]]
          filename
The preload option automatically loads the resource whenever the application is run. loadoncall loads the resource only when it is called.
If a fixed memory option is selected, the resource remains at a fixed memory address. Selecting moveable allows Windows to move the resource to compact and conserve memory. The last choice, discardable, allows Windows to discard the resource if it is no longer needed. However, it can be reloaded should a call be made requesting the particular resource. For example, making mybitmap loadoncall and discardable is as simple as entering the following modified single-line statement into the resource script:
myicon ICON myicon.ico
mycursor CURSOR mycursor.cur
mybitmap BITMAP LOADONCALL DISCARDABLE mybitmap.bmp
Compiling Resources
Resource script files must be compiled into resource files. The resource compiler is responsible for this operation. The resource compiler can be run from the command line or, preferably, with the use of the project utility.
The command to run the resource compiler includes the name of the resource script file, the name of the executable file that will receive the compiler’s binary format output, and any optional instructions.
The syntax for using the resource compiler from the command line is simple. From the command line, type
rc [[compiler options]] filename.rc [[executable filename]]
For example, invoking the resource compiler with the example resource script described earlier would look like one of the following three lines:
rc myres
rc myres.rc
rc -r myres.rc
The first two examples read the MYRES.RC resource script file, create the compiled resource file MYRES.RES, and copy the resources into the executable file MYRES.EXE. The third command performs the same actions, except that it does not put the resource into MYRES.EXE. If the third command were executed, the MYRES.RES binary file could be added to the MYRES.EXE file at a later date by using the following command structure:
rc myres.res
This causes the resource compiler to search for the compiled resource file (.RES) and place it into the executable file (.EXE) of the same filename.

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

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