Date: 02-16-2022
Return to Index
created by gbSnippets
'This snippet shows how to capture the dialog in two
'ways. First is to use keybd to simular Alt-PrintScreen.
'2nd is to capture screen, then copy only the area of the
'dialog using BitBlt.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE "gbSnapper.exe"
#Dim All
%Unicode=1
#Include "Win32api.inc"
Global hDlg, hDlg2 As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "",,,250,250, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 100, "Capture Dialog", 10,10,180,20
Control Add Button, hDlg, 200, "Capture Screen - Get Dialog", 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_InitDialog
Dialog New Pixels, hDlg, "#2", 40,100,120,100, %WS_OverlappedWindow To hDlg2
Dialog Show Modeless hDlg2
Case %WM_Command
Select Case Cb.Ctl
Case 100 : keybd_event(%VK_SnapShot, 1, 0, 0) 'place active dialog on clipboard
Case 200
Dialog Get Loc hDlg To x1,y1 'top,left
Dialog Get Size hDlg To w,h
CopyPartOfScreenToClipBoard x1,y1,w,h
Case 300
End Select
End Select
End Function
Sub CopyPartOfScreenToClipboard (x1 As Long, y1 As Long, w As Long, h As Long)
Local hBMP, hBMPDC, hDeskTopDC As Dword
'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
hDeskTopDC = GetDC(%Null)
BitBlt hBMPDC, 0,0,w,h, hDeskTopDC, x1,y1, %SRCCopy 'copy desktop image to
ReleaseDC(%Null,hDeskTopDC)
'send to clipboard
Clipboard Reset
Clipboard Set Bitmap hBMP
End Sub
'gbs_00768
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm