Date: 02-16-2022
Return to Index
created by gbSnippets
'GDI uses the concept of Pens and Brushes to specify the
'style and color of drawings.
'A pen defines the line color and line style.
'A brush defines the file color.
'Not all GDI functions use a pen or brush.
'Using pens and brushes starts with getting a handle, which
'must be deleted before your program ends.
'To create a pen, use CreatePen API
hGreenPen = CreatePen(nPenSTyle, nWidth, nColor)
'Typical pen styles are:
PS_SOLID - solid
PS_DASH - dashed
PS_DOT - dotted
PS_DASHDOT - alternating dashes/dots
PS_DASHDOTDOT - alternating dashes/double dots
PS_NULL - nvisible
'Example of green pen, 1 pixel wide
hPen = CreatePen(%PS_SOLID, 1, RGB(0,255,0))
'Multiple pens can be created. Once created a pen must
'be selected as the current pen using the SelectObject API
'When done using our pen, we must re-select the old pen,
'whose handle is returned by SelectObject.
'Example of selecting green pen, 1 pixel wide
hGreenPen = CreatePen(%PS_SOLID, 1, RGB(0,255,0))
oldPen = SelectObject(hdc,greenPen);
... do somthing
SelectObject hDC, oldPen 'when done, re-select the old pen
'Brushes also must be create, using the CreateSolidBrush API for
'a solid bursh or CreateBrushIndirect for a brush with specific styles
'or even using a loaded bitmap (use CreatePatternBrush with bitmap)
'Example of solid brush
hBlueBrush = CreateSolidBrush( RGB(0,0,255) )
'Example of using solid brush to fill a rectangle
Local R as Rect
R.nleft = 10
R.nright = 100
R.ntop = 10
R.nottom =200
FillRect(hdc, R, hblueBrush);
'The are pre-existing pens and brushes, handles to which can be
'acquired using GetStockObject API. The PowerBASIC equates for
'these are :
%WHITE_BRUSH = 0
%LTGRAY_BRUSH = 1
%GRAY_BRUSH = 2
%DKGRAY_BRUSH = 3
%BLACK_BRUSH = 4
%NULL_BRUSH = 5
%HOLLOW_BRUSH = %NULL_BRUSH
%WHITE_PEN = 6
%BLACK_PEN = 7
%NULL_PEN = 8
'gbs_00498
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm