RBitmapImage& RWinColorPalette::GetPaletteBitmapImage( ) { static BOOLEAN m_fPaletteInitialized = FALSE; static RBitmapImage m_biPalette; if ( !m_fPaletteInitialized ) { // find the resource in the resource file HRSRC hRsrc = FindResource( AfxGetResourceHandle(), MAKEINTRESOURCE( m_uPaletteBitmapID ), RT_BITMAP ); if ( hRsrc != NULL ) { // get a handle to the resource data HGLOBAL hTemp = LoadResource( AfxGetResourceHandle(), hRsrc ); if ( hTemp != NULL ) { // Initlize the palette bitmap with the resource data m_biPalette.Initialize( LockResource( hTemp ) ); // unlock and free the resource UnlockResource( hTemp ); FreeResource( hTemp ); } else AfxThrowResourceException( ); } else AfxThrowResourceException( ); m_fPaletteInitialized = TRUE; COLORMAP crColorMap[] = { { RGB( 255, 255, 255 ), GetSysColor( COLOR_BTNHIGHLIGHT ) }, { RGB( 192, 192, 192 ), GetSysColor( COLOR_BTNFACE ) }, { RGB( 128, 128, 128 ), GetSysColor( COLOR_BTNSHADOW ) } }; RIntPoint ptCells[] = { FindColor( crColorMap[0].from ), FindColor( crColorMap[1].from ), FindColor( crColorMap[2].from ) }; void* pRawData = m_biPalette.GetRawData(); RGBQUAD* pColorData = (RGBQUAD *) RBitmapImage::GetColorData( pRawData ); LPBYTE pImageData = (LPBYTE) RBitmapImage::GetImageData( pRawData ); for (int j = 0; (LPVOID) pColorData < (LPVOID) pImageData; j++, pColorData++) { for (int i = 0; i < NumElements( crColorMap ); i++) { if (crColorMap[i].from == RGB( pColorData->rgbRed, pColorData->rgbGreen, pColorData->rgbBlue )) { pColorData->rgbBlue = GetBValue( crColorMap[i].to ); pColorData->rgbRed = GetRValue( crColorMap[i].to ); pColorData->rgbGreen = GetGValue( crColorMap[i].to ); pColorData->rgbReserved = 0; } } if (j == 9) { // We only need to look at the system colors, so // jump to the last 10 entries in the palette. pColorData += 235; } } m_biPalette.UpdatePalette(); // // Relace the cells that got remapped // ROffscreenDrawingSurface dsMem; dsMem.SetImage( &m_biPalette ); RSolidColor rSolid; for (int i = 0; i < NumElements( ptCells ); i++) { if (ptCells[i].m_x >= 0 && ptCells[i].m_y >= 0) { RIntRect rcCell( RIntSize( kCellSize.m_dx - 2, kCellSize.m_dy - 2 ) ); rcCell.Offset( RIntSize( ptCells[i].m_x + 1, ptCells[i].m_y + 1 ) ); rSolid = crColorMap[i].from; RColor rColor( rSolid ); dsMem.SetFillColor( rColor ); dsMem.FillRectangle( rcCell ); } } dsMem.ReleaseImage(); } return m_biPalette; }