Attribute VB_Name = "Graphics"
'Lord Orwell's graphics.bas v 1.0
Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
  ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal _
  nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Declare Function GetDC Lib "user32" (ByVal Hwnd As Long) As Long
Declare Function GetWindowRect& Lib "user32" (ByVal Hwnd As Long, lpRect As RECT)
Declare Function StretchBlt& Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, _
  ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As _
  Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal _
  nSrcHeight As Long, ByVal dwRop As Long)
  
Declare Function UpdateWindow& Lib "user32" (ByVal Hwnd As Long)
Private Const SRCCOPY = &HCC0020
Type RECT
     left As Long
     top As Long
     right As Long
     bottom As Long
End Type

Sub CopyWindowGraphics(SrcHwnd As Long, DestHwnd As Long, XStart As Long, YStart As Long, XEnd As Long, YEnd As Long)
'keep in mind that while it is possible to read the bitmap pictur
'of any window with this subroutine, only certain window classes
'are designed to show the result.  in vb:  Form, Picture box, richtextbox, etc.
'You can't draw on a standard text box, command button, etc.
Dim hWndDeskTop As Long, SrcHDC As Long
  SrcHDC = GetDC(SrcHwnd)
  DestHDC = GetDC(DestHwnd)
  Call BitBlt(DestHDC, 0, 0, XEnd - XStart, YEnd - YStart, SrcHDC, XStart, YStart, SRCCOPY)
  UpdateWindow (DestHwnd) 'necessary to show what you did.

End Sub

Sub CopyWindowGraphicsMakeFit(SrcHwnd As Long, DestHwnd As Long, XStart As Long, YStart As Long, XEnd As Long, YEnd As Long)
 'this function will not work with a form.  Use CopyWindowGraphicsToForm
 Dim err As Long
 Dim DestRect As RECT
 Dim SrcHDC As Long
 Dim DestHDC As Long
 SrcHDC = GetDC(SrcHwnd)
 DestHDC = GetDC(DestHwnd)
 Call GetWindowRect(DestHwnd, DestRect)
 Call StretchBlt(DestHDC, 0, 0, DestRect.right - DestRect.left + 1, DestRect.bottom - DestRect.top + 1, SrcHDC, XStart, YStart, XEnd, YEnd, SRCCOPY)
 UpdateWindow (DestHwnd) 'necessary to show what you did.
'if your window gets another window shown over the top of it, it will probably
'need to be updated again.
End Sub


