Can anyone provide me with a sample using CreateHatchBrush
2 answers
The easiest option is to use GDI + for this. Here's a sample of a quick and dirty rendering of a shadow:
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!
0
source to share
I don't have a sample, but some hints about the general use of brushes on Windows.
CreateHatchBrush()
returns a handle. You must use this handle to make this brush the current brush in the Device Context you are using for rendering. Call the "Device Context" function SetObject
(regular Windows version of GDI):
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);
0
source to share