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"
Global hDlg, hDlg2 As Dword
Function PBMain() As Long
Dialog New Pixels, 0, "",,,250,250, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, 200, "Capture Screen - Get Union", 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 200 : CopyPartOfScreenToClipBoard hDlg, hDlg2
End Select
End Select
End Function
Sub CopyPartOfScreenToClipboard (hWnd1 As Dword, hWnd2 As Dword)
Local w,h As Long
Local hBMP, hBMPDC, hDeskTopDC As Dword
Local rWnd1, rWnd2, rUnion As Rect
'get hWnd1 bounding rectangle - hWnd1 is the MAIN
Dialog Get Loc hWnd1 To rWnd1.nLeft, rWnd1.nTop
Dialog Get Size hWnd1 To w,h
rWnd1.nRight = rWnd1.nLeft + w '- 1
rWnd1.nBottom = rWnd1.nTop + h '- 1
'get hWnd2 bounding rectangle - hWnd2 is a SECONDARY dialog
Dialog Get Loc hWnd2 To rWnd2.nLeft, rWnd2.nTop
rWnd2.nLeft = rWnd2.nLeft + rWnd1.nLeft
rWnd2.nTop = rWnd2.nTop + rWnd1.nTop
Dialog Get Size hWnd2 To w,h
rWnd2.nRight = rWnd2.nLeft + w '- 1
rWnd2.nBottom = rWnd2.nTop + h '- 1
UnionRect rUnion, rWnd1, rWnd2
'show the results
? "Boundary coordiantes of hWnd1, hWnd2, and their union:" + $CrLf + _
Str$(rWnd1.nLeft) + Str$(rWnd1.nTop) + Str$(rWnd1.nRight) + Str$(rWnd1.nBottom) + $CrLf + _
Str$(rWnd2.nLeft) + Str$(rWnd2.nTop) + Str$(rWnd2.nRight) + Str$(rWnd2.nBottom) + $CrLf + _
Str$(rUnion.nLeft) + Str$(rUnion.nTop) + Str$(rUnion.nRight) + Str$(rUnion.nBottom)
'create memory bitmap the size of the union
w = rUnion.nRight - rUnion.nLeft + 1
h = rUnion.nBottom - rUnion.nTop + 1
Graphic Bitmap New w,h To hBMP
Graphic Attach hBMP,0
Graphic Get DC To hBMPDC
'bitblt union rectangle from the screen to the memory bitmap
hDeskTopDC = GetDC(%Null)
BitBlt hBMPDC, 0,0,w,h, hDeskTopDC, rUnion.nLeft,rUnion.nTop, %SRCCopy 'copy desktop image to
ReleaseDC(%Null,hDeskTopDC)
'send to clipboard
Clipboard Reset
Clipboard Set Bitmap hBMP
End Sub
'gbs_00769
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm