Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compile Exe
#Dim All
#Include "Win32API.inc"
%IDC_Graphic = 500
Global hDlg As Dword, iCount As Long, pt, ptA, ptB As Point
Function PBMain() As Long
Dialog New Pixels, 0, "Ready",300,300,300,300, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0, 300,300,%WS_Border Or %SS_Notify
Graphic Attach hDlg, %IDC_Graphic, ReDraw
Graphic Width 10
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Graphic
Incr iCount
GetCursorPos pt : ScreenToClient hDlg, pt
If iCount = 1 Then ptA = pt 'save point 1
If iCount = 2 Then ptB = pt 'save point 2
DrawDisplay 'draws box around point 1/2, depending on iCount
If iCount = 2 Then
Reset pt, ptA, ptB, iCount : Sleep 2000
DrawDisplay 'does NOT draw box around points 1/2 because iCount=0
End If
End Select
End Select
End Function
Sub DrawDisplay
'Graphic Attach hDlg, %IDC_Graphic 'required? not in this example
Graphic Clear
If iCount > 0 Then Graphic Box (ptA.x-10,ptA.y-10)-(ptA.x+10,ptA.y+10),,%Red 'Draw first point
If iCount > 1 Then Graphic Box (ptB.x-10,ptB.y-10)-(ptB.x+10,ptB.y+10),,%Red 'Draw second point
Graphic ReDraw
End Sub
http://www.garybeene.com/sw/gbsnippets.htm