Windows XP icon and cursor support

Support for Windows XP has ended

Microsoft ended support for Windows XP on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.

This article was previously published under Q307213
This article has been archived. It is offered "as is" and will no longer be updated.
This article discusses the following topics:
  • How Windows XP supports icons and cursors.
  • The changes that were made for high-color display devices.
  • The changes that were made for high-DPI (dots-per-inch) systems. A high-DPI system has a primary display device with greater than or equal to 150 DPI.

Icon colors

The primary improvement to icons is that Microsoft Windows XP supports high-color and alpha-channel icons. Icons and cursors in Windows XP can be any color depth, to a maximum of 32 Bits-Per-Pixel (BPP). For an icon to contain an alpha channel, it must be 32 BPP, of which 24 bits are used for color red-green-blue (RGB) values, and 8 bits are used to store the alpha channel.

Icon selection

When an icon is loaded, the system does the following:
  • First, the system consults the color depth of the primary monitor for the target color depth (because currently there are no APIs by which you can provide an explicit color depth).
  • Second, the system consults the system metrics to obtain the values for the target width and height.
  • Third, the system assigns to each candidate image in the icon resource or file a score that is based on how far the image departs from the target.
The scoring algorithm assumes the following:
  • It is not a good idea to compress colors. The mechanical process of reducing the color space frequently produces undesirable results, especially in the low end of the color space. If you compress an 8-BPP color image (which is 256 colors) into a 4-BPP representation (only 16 colors), you probably receive poor quality results. In such a case, a manually customized image that has a lower color depth would look better.
  • It is not a good idea to expand width and height. Compression algorithms are frequently more successful than stretching algorithms.
After the system assigns the scores, the system loads the icon candidate that has the lowest score. The following points describe the formula that the system uses to calculate the values of the icons:
  • Basic deltas are calculated from the differences in color depth (expressed in bits-per-pixel), in width, and in height between the target and the candidate.
  • The width and height deltas are then multiplied by 2 if they require stretching (hence, icons that require stretching are known as punished).
  • The color depth delta is always multiplied by 2 to give it more weight.
  • Finally, the absolute values of all of these deltas are added together to produce a final score.
Note Unlike earlier versions of Windows, the scoring algorithm in Windows XP does not stretch (or, "punish") the color depth by a factor of 2 if color compression is involved. This change is because the bit depths implicitly do color compression, except for the high-color cases.

Consider the following bit depths: 2 BPP, 4 BPP, and 8 BPP. These are consecutive bit depths, and the delta between 2 BPP and 4 BPP is smaller than the delta between 4 BPP and 8 BPP. Therefore, the system would already select the lower color depth. Relaxing this punishment allows us to select a 32-BPP icon on a 24-BPP display device, instead of selecting the 8-BPP icon. This was necessary because the new user interface benefits from alpha-blended icons, but 24-BPP surfaces typically perform better than 32-BPP surfaces perform.

Cursor colors

A cursor is just an icon that has a hot spot that the system uses to interpret your intent when you point at something on the screen. Therefore, cursors are almost exactly the same as icons in their file format, except that some of the color information that is stored by an icon is used to store the hot spot in a cursor file. This similar file format limits cursors because when Windows XP implements the cursor loader, the color depth for a cursor is assumed to be 1 BPP.

Note The cursor is loaded properly at whatever color depth the cursor was authored. However, the system cannot distinguish between multiple candidates in the same cursor file or resource that differ only by their color depths. Icons, however, fully support multiple icon candidates with varying color depths.

Note Although it is possible for the system to examine the actual bitmaps that compose the cursor candidates to retrieve their actual color depths, Windows currently does not do this.

In the past, cursors were low-color, typically black and white, although some schemes included color versions. Windows XP supports 32-BPP cursors, which increases the possibilities for their use, although performance may suffer if your hardware is not adequately accelerated.

Note The system setting for a shadow under the mouse pointer is ignored if the cursor has an alpha channel (32 BPP).

For these reasons, Microsoft recommends that cursor sets be authored only at a single color depth. Microsoft also recommends the use of multiple sizes in the cursor set, especially if you might use the cursors on a high-DPI system.

Cursor sizes

Although cursors can, in theory, be any size, the system imposes a standard size that is exposed by means of the SM_CXCURSOR and SM_CYCURSOR values. These metrics are read-only. On standard, low-DPI systems, these metrics are set to 32x32 pixels (32 bytes/row). When the system loads cursors by means of the standard LoadCursor function, the cursor is stretched to this dimension.

Most system cursors appear smaller than 32x32 and do not use some of the space around the cursor. The cursors in the extra-large schemes use more of the available 32x32 area. Windows XP does not include any system cursors that are larger than 32x32. (If larger cursors were included, they would be stretched down to 32x32 when the standard APIs load the cursors.)

For high-DPI systems, Windows XP has adjusted the SM_CXCURSOR and SM_CYCURSOR values to be 64x64 pixels. This size adjustment is to prevent the mouse pointer from virtually disappearing because it is too small to be effectively used. Although the other aspects of the system scale with DPI, the mouse pointer does not scale. Microsoft does not try to enforce a DPI-independent size for the mouse pointer.

The system also provides the SetSystemCursor API function that you can use to change the system cursor for specific categories. You can use this function to set a cursor of any size. However, you must call the function programmatically, and you can only use it to set a cursor for a specific category. You cannot use it to make all cursors on the system the same size.

For cursor sets that you want to use on high-DPI systems, Microsoft recommends that you author them with both 32x32 and 64x64 candidates. The system will select the appropriate candidate during loading, depending on the DPI of the system.

Cursor scaling problems

Occasionally, the system must scale a cursor. By default, the system performs a nearest-neighbor stretch. The results, although fast, are very pixilated; therefore, half-tone stretching has been enabled to produce a little better results. Unfortunately, half-tone stretching works best with source images that have many colors, and cursors typically have very few colors. Therefore, the stretching algorithms are limited in how pleasing the results can appear.

Most icons are authored at 32x32 pixels, and most systems do not stretch icons because they are low-DPI systems. However, High-DPI systems do stretch the default system cursors. Because half-tone stretching produces better visual results than pixilation, half-tone stretching is enabled.

Additionally, the stretching algorithms typically perform differently on the transparency mask and color images, resulting in a divergence. The mask is black and white; therefore, there can be no interpolated colors between adjacent pixels. The color image, however, frequently can support the interpolated colors. The frequent result is that the mask is shaped a little different from what you intended. This can lead to heavy borders, and in some cases, other incorrect visual effects along the borders. Cursors that contain an alpha channel instead of a transparency mask do not have this problem because the alpha channel is implicitly tied to the color information.

Finally, as the cursor is stretched, the hot spot (which is a single pixel) is more likely to move away from its intended position. As the cursor is scaled, the hot spot is adjusted, but with less refinement than the color information.

Article ID: 307213 - Last Review: 12/06/2015 05:19:23 - Revision: 2.1

Microsoft Windows XP Professional, Microsoft Windows XP Home Edition

  • kbnosurvey kbarchive kbinfo kbicon kbresource kbcursor kbpubtypekc KB307213