How to Shade Images to Look Like Windows 95 Active IconLast reviewed: September 29, 1995Article ID: Q128786 |
The information in this article applies to:
SUMMARYThis article shows by example how to display an image or an icon in a shaded state, as Windows 95 does for the active icon.
MORE INFORMATION
Step-by-Step ProcedureTo obtain the shaded look for your image or icon, follow these six steps:
Sample CodeThe following function implements these six steps to shade a rectangular area on a device context:
// ShadeRect // hDC : the DC on which the area is to be shaded // lpRect : the coordinates within which to shadeBOOL ShadeRect( HDC hDC, LPRECT lpRect ) { COLORREF crHighlightColor, crOldBkColor, crOldTextColor; HBRUSH hBrush, hOldBrush; HBITMAP hBitmap, hBrushBitmap, hOldMemBitmap; int OldBkMode, nWidth, nHeight; HDC hMemDC; RECT rcRect = { 0, 0, 0, 0}; // The bitmap bits are for a monochrome "every-other-pixel" // bitmap (for a pattern brush) WORD Bits[8] = { 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa, 0x0055, 0x00aa }; // The Width and Height of the target area nWidth = lpRect->right - lpRect->left + 1; nHeight = lpRect->bottom - lpRect->top + 1; // Need a pattern bitmap hBrushBitmap = CreateBitmap( 8, 8, 1, 1, &Bits ); // Need to store the original image hBitmap = CreateCompatibleBitmap( hDC, nWidth, nHeight ); // Need a memory DC to work in hMemDC = CreateCompatibleDC( hDC ); // Create the pattern brush hBrush = CreatePatternBrush( hBrushBitmap ); // Has anything failed so far? If so, abort! if( (hBrushBitmap==NULL) || (hBitmap==NULL) || (hMemDC==NULL) || (hBrush==NULL) ) { if( hBrushBitmap != NULL ) DeleteObject(hBrushBitmap); if( hBitmap != NULL ) DeleteObject( hBitmap ); if( hMemDC != NULL ) DeleteDC( hMemDC ); if( hBrush != NULL ) DeleteObject( hBrush ); return FALSE; } // Select the bitmap into the memory DC hOldMemBitmap = SelectObject( hMemDC, hBitmap ); // How wide/tall is the original? rcRect.right = nWidth; rcRect.bottom = nHeight; // Lay down the pattern in the memory DC FillRect( hMemDC, &rcRect, hBrush ); // Fill in the non-color pixels with the original image BitBlt( hMemDC, 0, 0, nWidth, nHeight, hDC, lpRect->left, lpRect->top, SRCAND ); // For the "Shutdown" look, use black or gray here instead crHighlightColor = GetSysColor( COLOR_HIGHLIGHT ); // Set the color scheme crOldTextColor = SetTextColor( hDC, crHighlightColor ); crOldBkColor = SetBkColor( hDC, RGB(0,0,0) ); SetBkMode( hDC, OPAQUE ); // Select the pattern brush hOldBrush = SelectObject( hDC, hBrush ); // Fill in the color pixels, and set the others to black FillRect( hDC, lpRect, hBrush ); // Fill in the black ones with the original image BitBlt( hDC, lpRect->left, lpRect->top, nWidth, nHeight, hMemDC, 0, 0, SRCPAINT ); // Restore target DC settings SetBkMode( hDC, OldBkMode ); SetBkColor( hDC, crOldBkColor ); SetTextColor( hDC, crOldTextColor ); // Clean up SelectObject( hMemDC, hOldMemBitmap ); DeleteObject( hBitmap ); DeleteDC( hMemDC ); DeleteObject( hBrushBitmap ); SelectObject( hDC, hOldBrush ); DeleteObject( hBrush ); return TRUE;}
|
Additional reference words: 4.00 hatch darken shadow
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |