Public 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 hDCSrc As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long Public Declare Function GetDesktopWindow Lib "user32" () As Long Public Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long Public Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc _ As Long) As Long Private Sub PrintScreen() Dim r As Long Dim hWndDesk As Long Dim hDCDesk As Long Dim LeftDesk As Long Dim TopDesk As Long Dim WidthDesk As Long Dim HeightDesk As Long 'setup the screen coordinates (upper corner (0,0) and lower corner (Width,Height) LeftDesk = 0 TopDesk = 0 WidthDesk = Screen.Width \ Screen.TwipsPerPixelX HeightDesk = Screen.Height \ Screen.TwipsPerPixelY 'get the desktop handle and display context hWndDesk = GetDesktopWindow() hDCDesk = GetWindowDC(hWndDesk) 'copy the desktop to the picture box r = BitBlt(Picture1.hdc, 0, 0, WidthDesk, HeightDesk, hDCDesk, LeftDesk, TopDesk, _ vbSrcCopy) r = ReleaseDC(hWndDesk, hDCDesk) End Sub |