Bearing in mind I don't do graphics, I was surprised at just how 'simple' this was.
EDIT: Just seen JM's edit so I guess they already know how to do this.Code:Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _ (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _ (ByVal hWnd1 As Long, _ ByVal hWnd2 As Long, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As Long Private 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 Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source Private Sub Command_Click() Dim lngHandle As Long Dim lngDCTarget As Long Dim lngDCSource As Long Dim lngRet As Long ' ' Find the Source Application ' lngHandle = FindWindow(vbNullString, "Doogle's Folly") If lngHandle <> 0 Then ' ' Find the PictureBox handle in the Source Application ' lngHandle = FindWindowEx(lngHandle, 0&, "ThunderPictureBoxDC", vbNullString) If lngHandle <> 0 Then ' ' Get the DC of the PictureBox in this Application ' lngDCTarget = GetDC(pic2.hwnd) If lngDCTarget <> 0 Then ' ' Get the DC of the PictureBox in the Source Application ' lngDCSource = GetDC(lngHandle) If lngDCSource <> 0 Then ' ' Copy the Source Picture to the Target PictureBox ' lngRet = BitBlt(lngDCTarget, 0&, 0&, pic2.ScaleWidth, pic2.ScaleHeight, lngDCSource, 0&, 0&, SRCCOPY) If lngRet = 0 Then Debug.Print "Error in BitBlt " & Err.LastDllError Else ' ' Release the DCs ' lngRet = ReleaseDC(lngHandle, lngDCSource) lngRet = ReleaseDC(pic2.hwnd, lngDCTarget) End If Else Debug.Print "Error obtaining Source DC " & Err.LastDllError End If Else Debug.Print "Error obtaining Target DC " & Err.LastDllError End If Else Debug.Print "Error finding Source PictureBox hwnd " & Err.LastDllError End If Else Debug.Print "Error finding Source Application " & Err.LastDllError End If End Sub




Reply With Quote