Using the Timer for a Status Report
The final program in this chapter is something I alluded to in Chapter 5. It's the only good use I've found for the GetPixel function.
WHATCLR (shown in Figure 8-7) displays the RGB color of the pixel currently under the hot point of the mouse cursor.
Figure 8-7. The WHATCLR program.
WHATCLR.C
|
WHATCLR does a little something different while still in WinMain. Because WHATCLR's window need only be large enough to display a hexadecimal RGB value, it creates a nonsizeable window using the WS_BORDER window style in the CreateWindow function. To calculate the size of the window, WHATCLR obtains an information device context for the video display by calling CreateIC and then calls GetSystemMetrics. The calculated width and height values of the window are passed to CreateWindow.
WHATCLR's window procedure creates a device context for the whole video display by calling CreateDC during the WM_CREATE message. This device context is maintained for the lifetime of the program. During the WM_TIMER message, the program obtains the pixel color at the current mouse cursor position. The RGB color is displayed during WM_PAINT.
You may be wondering whether that device context handle obtained from the CreateDC function will let you display something on any part of the screen rather than just obtain a pixel color. The answer is Yes. It's generally considered impolite for one application to draw on another, but it could come in useful in some odd circumstances.
No comments:
Post a Comment