Date: 02-16-2022
Return to Index
'Compilable Example: (Jose Includes)
created by gbSnippets
#Compiler PBWin 9, PBWin 10
#Compile Exe "gbSnapper.exe"
#Dim All
%Unicode=1
#Include "Win32api.inc"
Global hDlg As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "",,,250,250, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 200, "Capture Dialog Section", 10,35,180,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local h,w,x1,x2,y1,y2 As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case 200
x1 = 0 : y1 = 0 'position in Dialog
w = 200 : h = 100 'w/h in Dialog
SavePartOfDialogToFile x1,y1,w,h,"part.bmp" 'upper left coordinates plus width/height
End Select
End Select
End Function
Sub SavePartOfDialogToFile (ByVal x1 As Long, ByVal y1 As Long, w As Long, h As Long, fName$)
Local hBMP, hBMPDC, hDialogDC As Dword, pt As Point
'create memory bitmap the size of the dialog
Graphic Bitmap New w,h To hBMP
Graphic Attach hBMP,0
Graphic Get DC To hBMPDC
'bitblt dialog rectangle from the screen to the memory bitmap
hDialogDC = GetDC(hDlg)
BitBlt hBMPDC, 0,0,w,h, hDialogDC, x1,y1, %SRCCopy 'copy desktop image to
ReleaseDC(%Null,hDialogDC)
'save to file
Graphic Save fName$
'send to clipboard
Clipboard Reset
Clipboard Set Bitmap hBMP
End Sub
'gbs_00768
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm