I want to draw a shadow around a thumbnail in my software. It seems CreateHatchBrush can help but I do not know how to use it, can anyone provide me a sample in C++? Many thanks!
A:
I don't have a sample, but some hints on general usage of brushes in Windows.
CreateHatchBrush() returns a handle. You need to use that handle to make that brush the current brush in the Device Context you are using to render. Call the Device Context's SetObject function (plain Windows GDI calls version):
HDC myDC = GetDC (hWnd); //pass your window handle here or NULL for the entire screen
HBRUSH hatchBrush = CreateHatchBrush (HS_DIAGCROSS, RGB (255,128,0));
HBRUSH oldBrush = SelectObject (myDC, hatchBrush);
//draw something here
SelectObject (myDC, oldBrush); //restore previous brush
ReleaseDC (myDC);
karx11erx
2008-12-29 15:49:58
A:
The easiest option would be to use GDI+ to do this. Here's a quick and dirty shadow rendering sample:
void Render( HDC hdc )
{
Graphics gr( hdc );
Image image( L"sample.jpg" );
const int SHADOW_OFFSET = 7;
//
// draw shadow
//
SolidBrush shadow( Color( 190, 190, 190 ) );
Rect rc( 50, 50, image.GetWidth(), image.GetHeight() );
rc.Offset( SHADOW_OFFSET, SHADOW_OFFSET );
gr.FillRectangle( &shadow, rc );
//
// draw the image
//
gr.DrawImage( &image, 50, 50, image.GetWidth(), image.GetHeight() );
//
// draw a border
//
Pen border( Color( 0, 0, 0 ), 1 );
rc.Offset( -SHADOW_OFFSET, -SHADOW_OFFSET );
gr.DrawRectangle( &border, rc );
}
Hope this helps!
Ranju V
2008-12-30 00:51:30