The information in this article applies to:
SUMMARYWhen 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. MORE INFORMATION
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.
Note that half the time the custom bitmap is displayed (when the caret "blinks") the other half of the time the background is displayed, (between "blinks"). If the background color is light gray or lighter [RGB values (128, 128, 128) through (255, 255, 255)], then a black caret is usually desired. The process of creating a black caret is just as straightforward. Modify step 1 of the process given above to substitute the inverse of the background for the background bitmap. When the caret blinks, it will show black. The equation that corresponds to this case is NOT(inverse of background XOR background) = NOT(TRUE) = FALSE which corresponds to BLACK. To change the caret color to something other than black or white requires considerably more work, with much less reliable results because the application must solve the following equation:
where the value for the caret color must be determined given the
desired color. A series of raster operations is required to solve this
type of equation. (For more information on raster operations, see
chapter 11 of the "Microsoft Windows [3.0] Software Development Kit
Reference, Volume 2" or pages 573-585 of the "Microsoft Windows [3.1]
Software Development Kit Programmer's Reference, Volume 3: Messages,
Structures, and Macros.")
Even after solving this equation, the color actually displayed is controlled by Windows and the colors in the current system palette. With colors other than black or white, an exact match for the desired color may not be available. In that case, Windows will provide the closest match possible. Because the palette is a dynamic entity and can be modified at will, it is impossible to guarantee a particular result color in all cases. The colors black and white should be safe most of the time because it is quite unusual for an application to modify the reserved system colors. Even when an application does change the system palette, it most likely retains a true black and a true white. As long as a black and white remain in the palette (which is usually the case), this algorithm will provide a white or black caret. Additional query words: WIN16SDK
Keywords : kbCaret kbNTOS kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS |
Last Reviewed: January 27, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |