HOWTO: Control the Caret ColorID: Q84054
|
When an application creates a custom caret using a bitmap, it is possible to specify white or black for the caret color. In the case of Windows running on a monochrome display, the application can cause the caret to be the color of the display (white, green, amber, and so forth, as appropriate). However, because the caret color is determined by Windows at run time based on the hardware installed, the application cannot guarantee what color will be used under all circumstances. This article provides information about using color in a custom caret.
To create a caret, first create a bitmap with the desired pattern. To
display the caret, Windows exclusive-ORs (XORs) and takes the opposite
of the result (the NOT of the result) of the bitmap with the
background of the client window. Therefore, to create a white caret,
create a bitmap that when XOR'd with the window background will have
an opposite value that will create a white color. It is when the caret
blinks that Windows uses the reverse of the bitmap XOR'd with the
background to draw the caret; this creates the white blink seen on the
screen.
The bitmap for the caret cannot use a color palette. Windows does not
use the color values from the palette in its calculations but the
indices into the palette. While it is possible to use palette indices
successfully, perfect symmetry of the colors in the palette is
required. This is unlikely. For each color in the palette, its exact
opposite color must be in the palette, in the exactly opposite index
position.
However, when the application creates bitmaps itself, it has complete
control over the bits. Therefore, the application can create the
perfect counterpart that corresponds to the window background color.
If the application uses this information to create the caret bitmap,
when Windows creates the caret, it can choose the closest color
available in the system palette.
Therefore, to create a white caret (or a black one, if the screen has
too many light elements), the task is straightforward. Windows always
reserves a few colors in the system palette and makes them available
to all applications. On a color display, these colors include black
and white. On a monochrome display, these colors are whatever the
monochrome color elements are.
Because black and white (or the monochrome screen colors) are always
available, the application simply creates a bitmap that, when XOR'd
with the screen background color, produces black or white.
The technique involves one main principle: background XOR background =
FALSE. Anything XOR'd with itself returns FALSE, which in bitmap terms
maps to the color black.
The process of creating a caret from the background color involves the
four steps discussed below:
NOT(caret XOR background) = desired_color on the
"blink" of the caret.
Additional query words: WIN16SDK
Keywords : kbCaret kbNTOS kbGrpUser kbWinOS
Version :
Platform :
Issue type : kbhowto
Last Reviewed: March 7, 1999