Article ID: 128637
Article Last Modified on 2/22/2007
/*************************************************************
* *
* DrawBackgroundPattern() *
* *
* Purpose: This function draws a gradient pattern that *
* transitions between blue and black. This is *
* similar to the background used in Microsoft *
* setup programs. *
* *
*************************************************************/
void DrawBackgroundPattern(HWND hWnd)
{
HDC hDC = GetDC(hWnd); // Get the DC for the window
RECT rectFill; // Rectangle for filling band
RECT rectClient; // Rectangle for entire client area
float fStep; // How large is each band?
HBRUSH hBrush;
int iOnBand; // Loop index
// How large is the area you need to fill?
GetClientRect(hWnd, &rectClient);
// Determine how large each band should be in order to cover the
// client with 256 bands (one for every color intensity level)
fStep = (float)rectClient.bottom / 256.0f;
// Start filling bands
for (iOnBand = 0; iOnBand < 256; iOnBand++) {
// Set the location of the current band
SetRect(&rectFill,
0, // Upper left X
(int)(iOnBand * fStep), // Upper left Y
rectClient.right+1, // Lower right X
(int)((iOnBand+1) * fStep)); // Lower right Y
// Create a brush with the appropriate color for this band
hBrush = CreateSolidBrush(RGB(0, 0, (255 - iOnBand)));
// Fill the rectangle
FillRect(hDC, &rectFill, hBrush);
// Get rid of the brush you created
DeleteObject(hBrush);
};
// Give back the DC
ReleaseDC(hWnd, hDC);
}
Additional query words: 3.00 3.10 4.00 GRADIENT BACKGROUND DITHER
Keywords: kbhowto KB128637