Date: 02-16-2022
Return to Index
created by gbSnippets
'Creating shapes and filling them are one of the most common uses of GDI API.
'Here's a list of the drawing/painting GDI API and their arguments. These
'use logical coordinates. Lines/borders are drawn using the current DC pen
'and filled with the current brush (unless otherwise specified).
'Drawing Shapes
' - Chord hDC,x,y,x2,y2,xR1,yR1,xR2,yR2
' - Ellipse hDC,,x,y,x2,y2
' - FillREct hDC, pRECT, hbrush 'includes t/l but not r/b borders
' - FrameRect hDC, pRECT, hbrush 'one unit border
' - InvertRect hDC, pRECT
' - Pie hDC, x,y,x2,y2,xR1,yR1,xR2,yR2
' - Polygon hDC, pPOINTSarray.nVerticesCount
' - PolyPolygon hDC, pPOINTSarray,pIntArray,nPolygonCount
' - Rectangle hDC, x,y,x2,y2 'border by pen, fill by brush
' - RoundRect hDC, x,y,x2,y2,xEllipse,yEllipse 'xy is ellipse size
'Lines and Curves
' - AngleArc hDC,x,y,radius,angleStart,angleSweep
' - Arc hDC,x,y,x2,y2,xR,yR,xR2,yR2
' - ArcTo hDC,x,y,x2,y2,xR,yR,xR2,yR2
' - GetArcDirection hDC
' - LineDDA x,y,x2,y2,pCallback,pData
' - LineDDAProc CALLBACK LineDDAProc(x,y,pData)
' - LineTo hDC,x2,y2
' - MoveToEx hDC,x,y,pPOINT 'pPOINT gets previous position (can be NULL)
' - PolyBezier hDC,pPOINTarray,pointCount
' - PolyBezierTo hDC,pPOINTarray,pointCount
' - PolyDraw hDC,pPOINTarray,pTYPEarray
' - Polyline hDC,pPOINTarray,pointCount
' - PolylineTo hDC,pPOINTarray,pointCount
' - PolyPolyLine hDC,pPOINTarray,pPointCountarray
' - SetArcDirection hDC,dirConstant
'Useful structures:
Type RECT Type POINT Type tagPAINTSTRUCT
left x hDC 'handle to display DC to be used for painting
top y fErase 'says whether background s/b erased (0-no, all else yes)
right End Type rcPaint 'RECT in which painting is requested (device units)
bottom fRestore 'reserved
End Type fIncUpdate 'reserved
rgbReserved 'reserved
End Type
'Compilable Example: (Jose Includes)
'This code demonstrates drawing shapes directly on dialog. The DC of
'dialog is retreived and all of the drawing API act on that DC.
'The drawing that takes place in the WM_Paint event will automatically
'be refreshed as needed, whereas the drawing done by pushing the button
'will not be automatically refreshed.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
Global hDlg As DWord
Function PBMain () As Long
Dialog New Pixels, 0, "Draw on Dialog",,, 325,325, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 101, "Draw",10,10,50,20
Dialog Show Modal hDlg, Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local PS As PaintStruct, hDC As DWord
Select Case CB.Msg
Case %WM_Paint
hDC = BeginPaint(hDlg, PS)
Ellipse hDC, 20,40,80,100
Ellipse hDC, 220,40,280,100
Rectangle hDC, 100,100,200,150
RoundRect hDC, 20,300,300,200,150,150
EndPaint hDlg, PS
Case %WM_Command
If CB.Ctl = 101 Then
hDC = GetDC(hDlg)
Ellipse hDC, 120,40,150,70
ReleaseDC(hDlg,hDC)
End If
End Select
End Function
'gbs_00494
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm