//prototype for default arguments - add this to your header file
HBITMAP EmbossPattern( HBITMAP hBitmap, HBITMAP hbmPattern, HPALETTE hPal,
BOOL bRaised = TRUE,
COLORREF clrHighlight = GetSysColor( COLOR_BTNHIGHLIGHT ),
COLORREF clrShadow = GetSysColor( COLOR_BTNSHADOW ) );
/////////////////////////////////////////////////////////////////////////////////////
// EmbossPattern - Creates a 3D effect and draws the pattern on the foreground
// but leaves the background alone
// Returns - A new bitmap containing the resulting effect
// hBitmap - Bitmap that contains the basic text & shapes
// hbmBackGnd - Contains the color image
// hPal - Handle of palette associated with hbmBackGnd
// bRaised - True if raised effect is desired. False for sunken effect
// xDest - x coordinate - used to offset hBitmap
// yDest - y coordinate - used to offset hBitmap
// clrHightlight - Color used for the highlight edge
// clrShadow - Color used for the shadow
//
// Note - 1. Neither of the bitmap handles passed in should be selected
// in a device context.
// 2. The pixel at 0,0 in hBitmap is considered the background color
//
HBITMAP EmbossPattern( HBITMAP hBitmap, HBITMAP hbmPattern, HPALETTE hPal,
BOOL bRaised, COLORREF clrHighlight, COLORREF clrShadow)
{
const DWORD PSDPxax = 0x00B8074A;
BITMAP bmInfo ;
HBITMAP hbmOld, hbmShadow, hbmHighlight, hbmResult, hbmOldMem, hbmMono ;
HBRUSH hbrPat ;
HDC hDC, hColorDC, hMonoDC, hMemDC ;
if( !bRaised )
{
// Swap the highlight and shadow color
COLORREF clrTemp = clrShadow;
clrShadow = clrHighlight;
clrHighlight = clrTemp;
}
// We create three monochrome bitmaps. One of them will contain the
// monochrome version of the bitmap primary bitmap. One will contain
// highlighted edge and the third will contain the shadow. These
// bitmaps are then used to paint the highlight and shadow on the
// background image.
// Set background color of bitmap for mono conversion
// We assume that the pixel in the top left corner has the background color
COLORREF clrBackGnd = GetPixel( hColorDC, 10, 10 );
SetBkColor( hColorDC, clrBackGnd ) ;
// Create the monochrome version of the bitmap.
hbmMono = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmMono ) ;
BitBlt( hMonoDC, 0, 0, bmInfo.bmWidth, bmInfo.bmHeight,
hColorDC, 0, 0, SRCCOPY ) ;
hbmMono = (HBITMAP)SelectObject( hMonoDC, (HGDIOBJ) hbmMono ) ;
// Now let's start working on the final image
SelectObject( hColorDC, hbmResult ) ;
// Select and realize the palette if one is supplied
if( hPal && GetDeviceCaps(hDC, RASTERCAPS) & RC_PALETTE )
{
::SelectPalette( hColorDC, hPal, FALSE );
::RealizePalette(hColorDC);
}
// Draw the pattern image - tile it if needed
for( int w = 0; w < bmInfo.bmWidth; w += bm.bmWidth )
{
for( int h = 0; h < bmInfo.bmHeight; h += bm.bmHeight )
BitBlt(hColorDC, w, h, bm.bmWidth, bm.bmWidth, hMemDC,
0, 0,SRCCOPY);
}
// Restore the old bitmap in the hMemDC
::SelectObject( hMemDC, hbmOldMem );