www.pudn.com > mfc资源大全1.rar > shade_image.shtml
Bitmap & Palette - Shade images to look like an active icon
The ShadeRect() function shown below executes the same effect on any rectangular area in the device context. It uses GetSysColor(COLOR_HIGHLIGHT) to determine what color to use but you can modify the function so that it takes in the color as one of the arguments. Doing so will allow you to give the image a disabled look when you specify the COLOR_GRAYTEXT color.
Here's what the function does:
void ShadeRect( CDC *pDC, CRect& rect )
{
// Bit pattern for a monochrome brush with every
// other pixel turned off
WORD Bits[8] = { 0x0055, 0x00aa, 0x0055, 0x00aa,
0x0055, 0x00aa, 0x0055, 0x00aa };
CBitmap bmBrush;
CBrush brush;
// Need a monochrome pattern bitmap
bmBrush.CreateBitmap( 8, 8, 1, 1, &Bits );
// Create the pattern brush
brush.CreatePatternBrush( &bmBrush );
CBrush *pOldBrush = pDC->SelectObject( &brush );
// Turn every other pixel to black
COLORREF clrBk = pDC->SetBkColor( RGB(255,255,255) );
COLORREF clrText = pDC->SetTextColor( RGB(0,0,0) );
// 0x00A000C9 is the ROP code to AND the brush with the destination
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
(DWORD)0x00A000C9); //DPa - raster code
pDC->SetBkColor( RGB(0,0,0) );
pDC->SetTextColor( GetSysColor(COLOR_HIGHLIGHT) );
// 0x00FA0089 is the ROP code to OR the brush with the destination
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(),
(DWORD)0x00FA0089); //DPo - raster code
// Restore the device context
pDC->SelectObject( pOldBrush );
pDC->SetBkColor( clrBk );
pDC->SetTextColor( clrText );
}
| Goto HomePage |
|
Contact me: zafir@home.com
|