How can I take a screen shot of the computer my VB program is runnning on?
Printable View
How can I take a screen shot of the computer my VB program is runnning on?
Or if you like to do things the hard way like me.....
VB Code:
Private Declare Function EmptyClipboard Lib "user32" () As Long Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function CloseClipboard Lib "user32" () As Long Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetDesktopWindow Lib "user32" () 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 CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long Private Const CF_BITMAP = 2 Public Function CopyScreenToClipboard() As Long Dim lngScreenDC As Long Dim lngScreenH As Long, lngScreenW As Long Dim lngDC As Long Dim lngBMP As Long, lngOrigBMP As Long ' get a handle to the screen lngScreenDC = GetDC(GetDesktopWindow) ' get the dimensions of the screen in pixels lngScreenH = Screen.Height \ Screen.TwipsPerPixelY lngScreenW = Screen.Width \ Screen.TwipsPerPixelX ' create a dc to temporarily hold the screen bmp lngDC = CreateCompatibleDC(lngScreenDC) ' create the bitmap in memory to hold picture of the screen lngBMP = CreateCompatibleBitmap(lngScreenDC, lngScreenW, lngScreenH) ' put the BMP created into the DC created lngOrigBMP = SelectObject(lngDC, lngBMP) ' blt the current state of the screen to the DC BitBlt lngDC, 0, 0, lngScreenW, lngScreenH, lngScreenDC, 0, 0, vbSrcCopy 'open the clipboard If OpenClipboard(Me.hwnd) Then ' clear the clipboard of current data If EmptyClipboard Then ' put the bitmap in clipboard SetClipboardData CF_BITMAP, lngBMP ' don't need to be thw owner of the clipboard anymore so let it go CloseClipboard Else MsgBox "Error saving data to clipboard!" End If Else MsgBox "Error saving data to clipboard!" End If ' free memory SelectObject lngDC, lngOrigBMP DeleteDC lngDC End Function Private Sub Command1_Click() CopyScreenToClipboard End Sub
;)
i got a error "invalid use of me keywork." and i need it to copy the screen shot to a file on the desktop or somethin so it can easily be sent to my tech support without any anoying messages.
k i got rid of the error but is there a way i could transfer it to a .gif file or something that can be easily transfered?
You'll have to use a third-party control from either http://www.activex.com/ or http://www.planetsourcecode.com/ . Intrinsically, VB cannot save files in JPEG or GIF format.