Date: 02-16-2022
Return to Index
created by gbSnippets
'PowerBASIC supplies a wide variety of Graphic statements, including the
'3 graphic targets - graphic control, graphic window and memory bitmap.
'But many simple drawing needs can be more easily met with the use of
'just a few API.
'hDC
'In general, the GDI API operate/draw on a DC (Device Context) that is
'associated with a window, screen, printer or other physical device. A
'DC can be acquired by using one of 4 API:
' - BeginPaint hDC = BeginPaint(hWnd, PS)
' - GetDC hDC = GetDC(hWnd) client area of window or screen
' - GetDCEx hDC = GetDCEx(hWnd, hrgnClip, flags) client area of window or screen
' - GetWIndowDC hDC = GetWindowDC(hWnd)
'The content of a DC is not persistent. That is, when another window covers,
'then uncovers the DC surface, the drawn content of the window disappears
'and must be redrawn by the application.
'Fortunately, when a Window is uncovered, a %WM_Paint message is sent to
'the application. So programmers typically place the drawing code with
'the %WM_Paint Event.
'See the compilable example below.
Type RECT Type POINT
left x
top y
right End Type
bottom
End Type
'Rectangles (coordinate math operations)
' - CopyRect pRECTto,pRECTfrom 'copies coordinates
' - EqualRect pRECTa,pRECTb 'equality comparison
' - InflateRect pRECT,hChange,wchange 'grow/shrink by change valus
' - IntersectRect pRECTintersection,pRECTa,pRECTb 'rectangle in common
' - IsRectEmpty pRECT 'zero size
' - OffsetRect pRECT,xMove,yMove 'move coordinates
' - PtInRect pRECT,xyPoint 'is point inside rectangle
' - SetRect pRECT,xLeft,yTop,xRight,yBottom 'sets new coordinates
' - SetRectEmpty pRECT 'sets all values to 0
' - SubtractRect pRECT,pRECTa,pRECTb 'pRECTa-pRECTb
' - UnionRect pRECT,pRECTa,pRECTb 'pRECT contains both a/b
'PaintStruct Structure
Type tagPAINTSTRUCT
hDC 'handle to display DC to be used for painting
fErase 'whether to erase background (0-no, all else yes)
rcPaint 'RECT in which painting is requested (device units)
fRestore 'reserved
fIncUpdate 'reserved
rgbReserved 'reserved
End Type
'Compilable Example: (Jose Includes)
#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",,, 150,100, %WS_OverlappedWindow To hDlg
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,20,80,80 'draw a circle
EndPaint hDlg, PS
CPrint "wm_paint" 'show how often we were here
End Select
End Function
Sub CPrint (SOut As String)
Static hConsole As Long, cWritten As Long, iCount As Long
Incr iCount : SOut = SOut + Str$(iCount)
If hConsole = 0 Then AllocConsole: hConsole = GetStdHandle(-11&)
WriteConsole hConsole, ByCopy sOut + $CrLf, Len(sOut) + 2, cWritten, ByVal 0&
End Sub
'gbs_00495
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm