Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
%IDC_Capture = 501
%IDC_Folder = 502
%IDC_Area = 503
%IDC_Graphic = 504
%IDC_GoTo = 505
Global hDlg As Dword
Global CapturePath As String
Global x1,y1,x2,y2 As Long
Function PBMain() As Long
Local w,h As Long
Dialog New Pixels, 0, " gbCapture",0,0,50,50, %WS_Sysmenu,%WS_EX_WindowEdge or %WS_EX_ToolWindow or %WS_EX_TopMost To hDlg
Control Add Button, hDlg, %IDC_Folder,"F", 0,0,15,25
Control Add Button, hDlg, %IDC_Area,"A", 15,0,15,25
Control Add Button, hDlg, %IDC_GoTo,"O", 30,0,15,25
Control Add Button, hDlg, %IDC_Capture,"Capture", 45,0,55,25
Desktop Get Size To w,h
Control Add Graphic, hDlg, %IDC_Graphic, "", 200,200,w,h
Graphic Attach hDlg, %IDC_Graphic
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
Settings_INI "get"
' SetWindowPos(hDlg, %HWND_TOPMOST, 0, 0, 0, 0, %SWP_NOMOVE Or %SWP_NOSIZE) 'on Top
Case %WM_Destroy
Settings_INI "save"
Case %WM_Command
Select Case cb.ctl
Case %IDC_Capture : CaptureArea
Case %IDC_Folder : SelectFolder
Case %IDC_Area : SelectArea
Case %IDC_GoTo : GoToFolder
End Select
End Select
End Function
Sub Settings_INI(Task$)
Local xResult, yResult, tempAsciiZ As Asciiz * %Max_Path
Local x,y As Long, INIFileName As AsciiZ * %Max_Path
INIFileName = EXE.Path$ + "gbcapture.ini" 'defines file name (any file name will work)
If Task$ = "get" Then
'get dialog top/left from INI file and use to set Dialog location
Getprivateprofilestring "All", "Left", "0", xResult, %Max_Path, INIFileName
Getprivateprofilestring "All", "Top", "0", yResult, %Max_Path, INIFileName
Dialog Set Loc hDlg, Val(xResult$), Val(yResult$) 'left/top
'get dialog width/height from INI file and use to set Dialog size
GetPrivateProfileString "All", "Width", "105", xResult, %Max_Path, INIFileName
GetPrivateProfileString "All", "Height", "45", yResult, %Max_Path, INIFileName
Dialog Set Size hDlg,Val(xResult$), Val(yResult$) 'width/height
'get string variables
Getprivateprofilestring "All", "CapturePath", "c:\temp", tempAsciiZ, %Max_Path, INIFileName
CapturePath = tempAsciiZ
'get numeric variables
Getprivateprofilestring "All", "x1", "100", tempAsciiZ, %Max_Path, INIFileName
x1 = Val(tempAsciiZ)
Getprivateprofilestring "All", "y1", "100", tempAsciiZ, %Max_Path, INIFileName
y1 = Val(tempAsciiZ)
Getprivateprofilestring "All", "x2", "600", tempAsciiZ, %Max_Path, INIFileName
x2 = Val(tempAsciiZ)
Getprivateprofilestring "All", "y2", "600", tempAsciiZ, %Max_Path, INIFileName
y2 = Val(tempAsciiZ)
End If
If Task$ = "save" Then
'save dialog size/location unless minimized or maximized
If IsFalse(IsIconic(hDlg) Or IsZoomed(hDlg)) Then
Dialog Get Loc hDlg To x,y
WritePrivateProfileString "All", "Left", Str$(x), INIFileName
WritePrivateProfileString "All", "Top", Str$(y), INIFileName
Dialog Get Size hDlg To x,y
WritePrivateProfileString "All", "Width", Str$(x), INIFileName
WritePrivateProfileString "All", "Height", Str$(y), INIFileName
End If
'save string variables
tempASCIIZ = CapturePath
WritePrivateProfileString "All", "CapturePath", tempASCIIZ, INIFileName
'save numeric variables
tempASCIIZ = Str$(x1)
WritePrivateProfileString "All", "x1", tempASCIIZ, INIFileName
tempASCIIZ = Str$(y1)
WritePrivateProfileString "All", "y1", tempASCIIZ, INIFileName
tempASCIIZ = Str$(x2)
WritePrivateProfileString "All", "x2", tempASCIIZ, INIFileName
tempASCIIZ = Str$(y2)
WritePrivateProfileString "All", "y2", tempASCIIZ, INIFileName
End If
End Sub
Sub CaptureArea
Local fName As String
Local hBMP As Dword
Static iCount As Long
keybd_event(%VK_SnapShot, 0, 0, 0)
Dialog DoEvents
Clipboard Get Bitmap To hBMP
Graphic Copy hBMP, 0
Incr iCount
fName = CapturePath + "\image" + LTrim$(Str$(iCount)) + ".bmp"
Graphic Save fName
End Sub
Sub SelectArea
End Sub
Sub SelectFolder
Local title$, start$, flags&, folder$
title$ = "Select folder where images will be placed!"
start$ = CapturePath
flags& = %BIF_ReturnOnlyFSDirs Or %BIF_DontGoBelowDomain Or %BIF_NoNewFolderButton
Display Browse hDlg, 100, 100, title$, start$, flags& To folder$ 'folder$ is "" if Cancel/Escape is pressed
If Len(folder$) Then CapturePath = folder$
End Sub
Sub GoToFolder
Local TargetPath as Asciiz * %Max_Path
TargetPath = CapturePath
ShellExecute(hDlg, "Open", TargetPath, $Nul, $Nul, %SW_Restore)
End Sub
'gbs_01002
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm