It All Begins with CObject

Chapter 4 - Advanced Visual C++ Features

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

Custom Icons, Cursors, and Bitmaps
Customizing a Windows application with your own icons, cursors, bitmaps, and dialog boxes is easy with Microsoft’s Visual C++ IDE. The Visual C++ IDE is not just a compiler. It is also an easy-to-use, powerful resource editor.
Creating Bitmap Resources
This section teaches you how to use the Visual C++ IDE to draw a bitmap. All other graphic figures, such as icons and cursors, can be created in a similar manner.
The Visual C++ IDE allows you to design device-independent color bitmap images. These bitmaps are functionally device independent with respect to resolution. The image file format allows you to create a bitmap that always looks the same, regardless of the resolution of the display on which it appears.
For example, a single bitmap might consist of four definitions (DIBs): one designed for monochrome displays, one for CGAs, one for EGAs, and one for VGAs. Whenever the application displays the bitmap, it simply refers to it by name; Windows automatically selects the icon image that is best suited to the current display.
Figure 4-1 shows the initial Visual C++ IDE window. The first step you must take to create an application resource such as a bitmap is to click on the Insert | Resource... menu item.
Figure 4-1: Preparing to create a new resource
The resulting dialog box, shown in Figure 4-2, shows the drop-down list that displays the kinds of resources available. Because we want to create a bitmap, click on the Bitmap resource. Simply press enter to confirm your selection.
Figure 4-2: Selecting bitmap resource from the list box
Creating a bitmap with the Visual C++ resource editor is just about as easy as creating a picture with Windows Paintbrush. The Visual C++ resource editor first presents you with a blank bitmap grid and the Drawing Tools toolbar.
You use the toolbar to select the brush size, the brush color, and various drawing modes, such as fills and predefined shapes. Figure 4-3 shows a completed bitmap.
Figure 4-3: A completed bitmap image
To set a resource’s properties, begin by pressing alt-enter. This step displays the particular resource’s Properties dialog box. Figure 4-4 shows the Bitmap Properties dialog box with the details of the bitmap’s width, height, colors, filename, and save compressed properties.
Figure 4-4: Viewing the Bitmap Properties dialog box
Creating Dialog Box Resources
The initial steps required for creating a dialog box resource are identical to those described previously for creating a bitmap resource. First, choose the kind of resource you wish to create; refer to Figure 4-2, shown earlier. However, this time, select the Dialog option.
Figure 4-5 shows a completed dialog box, the dialog box Objects toolbox (on the right side of the screen), and the Text Properties dialog box.
Figure 4-5: A completed dialog box
The Objects toolbox allows you to place a variety of controls in your dialog box design. These include (starting at the top and proceeding from left to right, not including the “arrow” selection control): Bitmap, Label, Edit box, Group Box, Button, Checkbox, Radio button, Combo box, List box, Horizontal scroll bar, Vertical scroll bar, Spin, Progress, Slider, Hot key, List Control, Tree Control, Tab Control, Animate, Rich Edit, Date Time, Month Calendar, IP Address, Custom, and Extended Combo box.
Figure 4-5, shown earlier, shows the company name label object selected. The Properties dialog box is brought to the foreground simply by double-clicking on the label object itself. This is a convenient alternative to returning to the main resource window. Each kind of control has its own set of properties.
The Cursor’s Hotspot Editor
A cursor resource differs slightly from a bitmap or an icon resource in that it can contain a hotspot. A cursor’s hotspot represents the part of the image that registers the cursor’s screen coordinates.
Creating a cursor involves the same initial steps used for creating bitmaps and dialog boxes. This process is started by first selecting the Insert | Resource... menu item command, and then choosing the cursor resource. Figure 4-6 shows a finished cursor design resembling a stylized up arrow.
Figure 4-6: The design of a unique cursor
A cursor’s hotspot is set by first clicking on the hotspot button to the right of the Hotspot: label in the Design toolbar. Once you have clicked on the button, simply move the mouse pointer into the cursor’s bitmap design and click on the appropriate cell.

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