Date: 02-16-2022
Return to Index
created by gbSnippets
'This code draws a focus rectangle (dotted line rectangle) over the dialog
'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, hDC As Dword, R, R2 As Rect
Function PBMain() As Long
Dialog New Pixels, 0, "Draw Rectangle",300,300,420,250, %WS_OverlappedWindow To hDlg
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
hDC = GetDC(hDlg)
DrawFocusRect hDC, R2
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 DrawFocusRect hDC, tempR : R2 = tempR Else Reset R2
ReleaseDc hDlg, hDC
End Sub
'gbs_00873
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm