Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
Private Type PICTDESC cbSize As Long pictType As Long hIcon As Long hPal As Long End Type Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" _ (lpPictDesc As PICTDESC, riid As Any, ByVal fOwn As Long, _ ipic As IPicture) As Long Private Declare Function GetDesktopWindow Lib "user32" () As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As _ Long Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hDC As Long, _ ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hDC As Long, _ ByVal hObject As Long) As Long Private Declare Function BitBlt Lib "gdi32" (ByVal hDCDest As Long, _ ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, _ ByVal nHeight As Long, ByVal lScreenDC As Long, ByVal XSrc As Long, _ ByVal YSrc As Long, ByVal dwRop As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long Private Declare Function GetWindowDC 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 Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, _ lpRect As RECT) As Long
Function GetScreenSnapshot(Optional ByVal hWnd As Long) As IPictureDisp Dim targetDC As Long Dim hDC As Long Dim tempPict As Long Dim oldPict As Long Dim wndWidth As Long Dim wndHeight As Long Dim Pic As PICTDESC Dim rcWindow As RECT Dim guid(3) As Long If hWnd = 0 Then hWnd = GetDesktopWindow GetWindowRect hWnd, rcWindow wndWidth = rcWindow.Right - rcWindow.Left wndHeight = rcWindow.Bottom - rcWindow.Top targetDC = GetWindowDC(hWnd) hDC = CreateCompatibleDC(targetDC) tempPict = CreateCompatibleBitmap(targetDC, wndWidth, wndHeight) oldPict = SelectObject(hDC, tempPict) BitBlt hDC, 0, 0, wndWidth, wndHeight, targetDC, 0, 0, vbSrcCopy tempPict = SelectObject(hDC, oldPict) DeleteDC hDC ReleaseDC GetDesktopWindow, targetDC With Pic .cbSize = Len(Pic) .pictType = 1 .hIcon = tempPict .hPal = 0 End With guid(0) = &H7BF80980 guid(1) = &H101ABF32 guid(2) = &HAA00BB8B guid(3) = &HAB0C3000 OleCreatePictureIndirect Pic, guid(0), True, GetScreenSnapshot
End Function |