Date: 02-16-2022
Return to Index
created by gbSnippets
'This code draws a focus rectangle (dotted line rectangle) over a Graphic
'Control in any direction from where the mouse is pressed.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg As Dword, R, R2 As Rect
%IDC_Graphic = 500
Function PBMain() As Long
Dialog New Pixels, 0, "Draw Rectangle",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,200,200
Graphic Attach hDlg, %IDC_Graphic
Graphic Render "cowgirl.bmp", (0,0)-(199,199)
Graphic Set Mix %Mix_NotXorSrc 'R2_NotXorPen
Graphic Style 1
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_LButtonDown
R.nLeft = Lo(Word, Cb.LParam) : R.nTop = Hi(Word, Cb.LParam)
Case %WM_MouseMove
R.nRight = Lo(Word, Cb.LParam) : R.nBottom = Hi(Word, Cb.LParam)
If (Cb.WParam And %MK_LBUTTON) Then DrawRect 1
Case %WM_LButtonUp
DrawRect 0
End Select
End Function
Sub DrawRect(Flag As Long) '1=moving 0=done
Local i As Long, tempR As Rect
Graphic Box (R2.nLeft,R2.nTop)-(R2.nRight,R2.nBottom), 0, %Black
tempR.nLeft = Min(R.nLeft,R.nRight)
tempR.nRight = Max(R.nLeft,R.nRight)
tempR.nTop = Min(R.nTop,R.nBottom)
tempR.nBottom = Max(R.nTop,R.nBottom)
If Flag Then
Graphic Box (tempR.nLeft,tempR.nTop)-(tempR.nRight,tempR.nBottom), %Black
R2 = tempR
Else
Reset R2
End If
End Sub
'gbs_00874
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm