Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE "gbSnapper.exe"
#Dim All
%Unicode=1
#Include "Win32api.inc"
%IDC_Graphic = 500
Global hDlg, hGraphic, hScreen, hCapture As Dword
Global pt, ptDrawOrig As Point
Global DrawInWork As Long
Function PBMain() As Long
Local w,h As Long
Desktop Get Size To w,h
Dialog New Pixels, 0, "",-3,0,w,h, %WS_Popup, %WS_EX_TOPMOST To hDlg
Control Add Graphic, hDlg, %IDC_Graphic, "", 0,0,w,h, %WS_CHILD OR %WS_VISIBLE OR %SS_OWNERDRAW
Graphic Attach hDlg, %IDC_Graphic, Redraw
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h,iReturn As Long, fName As Asciiz * %Max_Path
Select Case Cb.Msg
Case %WM_InitDialog
keybd_event(%VK_SnapShot, 0, 0, 0) 'screen image
Sleep 100
Clipboard Get Bitmap To hScreen
Graphic Copy hScreen, 0 : Graphic ReDraw
Case %WM_Destroy
w = Abs(ptDrawOrig.x - pt.x) + 1 : h = Abs(ptDrawOrig.y - pt.y) + 1
MsgBox "Selection placed on clipboard." + $crlf + "Size: " + str$(w) + " x" + str$(h), %MB_Ok or %MB_IconInformation, "gbSnapper"
Graphic Bitmap New w,h To hCapture : Graphic Attach hCapture,0
Graphic Copy hScreen, 0, (ptDrawOrig.x,ptDrawOrig.y)-(pt.x,pt.y) To (0,0)
Clipboard Reset : Clipboard Set Bitmap hCapture
fName = Exe.path$ + "gbsnapper.bmp"
Graphic Save fName 'save to file
iReturn = ShellExecute(hDlg, "Open", fName, $Nul, $Nul, %SW_ShowNormal) 'open
Case %WM_MouseMove
MousePtr 2 : Function = 1 'maintain cross hairs
Case %WM_SetCursor
Dialog Get Client hDlg To w,h : GetCursorPos pt : ScreenToClient hDlg, pt 'get mouse position in dialog coordinates
Select Case Hi(Word, Cb.LParam)
Case %WM_LButtonDown
DrawInWork = 1 : ptDrawOrig = pt 'start drawing line
Case %WM_MouseMove
If DrawInWork Then
Graphic Copy hScreen, 0 'put screen image in graphic control
Graphic Box (ptDrawOrig.x, ptDrawOrig.y) - (pt.x, pt.y),, %Red 'draw rectangle that follows the mouse
Graphic Redraw
End If
Case %WM_LButtonUp : Dialog End hDlg 'exit when left mouse button is released
End Select
End Select
End Function
'gbs_00707
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm