The SDKPAINT Tool

SDKPAINT is one of the most important development tools in the Windows Software Development Kit. The program allows you to create bitmaps, icons, and cursors for use in your Windows programs. Icons and cursors are both variations of bitmaps, so it will be helpful to examine bitmaps first.

A bitmap is an array of bits where one or more bits corresponds to each display pixel. In a monochrome bitmap, one bit corresponds to one pixel. (In the simplest case, a 1 bit represents white and a 0 bit represents black. However, bitmaps are often used in logical operations rather than merely to create simple drawings.) In a color bitmap, multiple bits correspond to each pixel to represent color. SDKPAINT supports the creation of monochrome bitmaps and 16-color bitmaps. In a 16-color bitmap, 4 bits are required for each pixel.

A bitmap may have any number of rows and columns. (However, the bitmaps you create in SDKPAINT are limited to 72 rows and 72 columns. You can create larger bitmaps in PAINTBRUSH.) Bitmaps are stored in files with a .BMP extension. (I'll discuss the format of the bitmap file in Chapter 13.)

You can also create icons and cursors in SDKPAINT. Icons and cursors are very similar, and they are both variations of bitmaps.

Windows displays icons and cursors on the screen in a pixel size that depends on the resolution of the video display. This ensures that the icons and cursors are neither too large nor too small. A program can obtain these pixel dimensions using the GetSystemMetrics function with parameters of SM_CXICON, SM_CYICON, SM_CXCURSOR, and SM_CYCURSOR. On most video displays, the dimensions of icons and cursors are identical. To keep it simple in the following discussion, I'll refer only to icons, but keep in mind that everything I say applies to cursors also.

On an IBM Color Graphics Adapter (CGA), the width of an icon is 32 pixels and the height is 16 pixels. On an Enhanced Graphics Adapter (EGA), Video Graphics Array (VGA), and the IBM 8514/A video adapter, the icons are 32 pixels wide and 32 pixels high. For higher-resolution adapters, icons could be displayed as 64 pixels by 64 pixels.

Each .ICO file can contain multiple icon images, each one designed for particular resolutions and color capabilities of the various video adapters on which your Windows program can run. SDKPAINT supports four different image formats. When you create a new icon file (by selecting New from SDKPAINT's File menu), you select one of these four formats. After creating an icon in this format, you can then select another of the four formats from the New option on the Image menu. These four formats are:

32 pixels by 16 pixels with 2 colors (monochrome)

32 pixels by 32 pixels with 2 colors (monochrome)

32 pixels by 32 pixels with 8 colors

32 pixels by 32 pixels with 16 colors

The first format is for the CGA, and the second is for other video adapters (EGA, VGA, and 8514/A) running in a monochrome mode. The third and fourth are for non-CGA adapters running in color modes. The 8-color format is of limited use: SDKPAINT actually uses a 16-color format internally and when saving the image to the file, but allows you to color it with only 8 colors. The EGA, VGA, and 8514/A are all capable of 16 colors.

You don't need to create icon images in all four formats. When a program contains an icon resource, Windows will choose the format that most closely approximates the size and color capabilities appropriate to the video adapter. For example, if you create only 32-by-32-pixel icons and your program is run on a CGA, Windows will display the icon using every other row of pixels, effectively compressing the height of the icon.

If you create only a 32-by-32 icon with 16 colors, use color sparingly because the colors can be approximated only with gray shades (or converted to black or white) when running with a monochrome display. All the icons and cursors in the programs in this chapter were created in the 32-by-32 monochrome format.

When you create an icon image in one of the four formats, SDKPAINT actually stores it as two bitmaps—a monochrome bitmap ”mask“ and a monochrome or color bitmap image. Icons are always rectangular, but this mask allows the icon to appear to be nonrectangular. That is, part of the icon allows the background against which the icon is displayed to be visible. The icon can also contain areas that invert the background color.

These two options are indicated in SDKPAINT by radio buttons labeled ”Screen“ and ”Inverse.“ After selecting ”Screen,“ anything you draw in the icon will be transparent, and after selecting ”Inverse,“ anything you draw in the icon will invert the background. You can select different background colors to see how this looks. The icons and cursor in Figure 8-1 are shown against a light gray background. The light gray areas were colored using the ”Screen“ option, and the dark gray areas were colored using the ”Inverse“ option.

For a monochrome icon, the following table shows how SDKPAINT constructs the two bitmaps that describe the icon:

Color: Black White Screen Inverse Screen

Mask Bitmap: 0 0 1 1
Image Bitmap: 0 1 0 1

When displaying the icon, Windows first uses a bitwise AND operation of the display and the first bitmap. The display pixels corresponding to 0 bits from the first bitmap all become 0's, which are black. The display pixels corresponding to 1 bit remain the same. This is shown in the following logic table.

  Display Pixel    
Mask Bit 0 1  

0 0 0  
1 0 1  

Next, Windows performs a bitwise exclusive OR operation of the image bitmap and the display. A 0 in the second bitmap leaves the display pixel the same; a 1 in the second bitmap inverts the display pixel. Here's the logic table:

  Display Pixel    
Image Bit 0 1  

0 0 1  
1 1 0  

Using C notation for the operations, the display is altered by the following formula:

Display = (Display & Mask) ^ Image

For a 16-color icon, the mask bitmap is still monochrome and constructed as shown above. The image bitmap contains 4 bits per pixel to represent 16 colors. All four bits are set to 1 for areas of the icon that invert the background.

Earlier I said that when talking about bitmaps, 0 does not necessarily mean black, and 1 does not necessarily mean white. As you can see here, it depends on how Windows uses the bitmaps. (I'll discuss this more in Chapter 13.)

In RESOURC1, I've defined the window class to make the background of the client area be COLOR_WINDOW. You may want to bring up the Windows Control Panel program and change the window color to see how the icon and cursor invert colors.