VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Capture desktop/Screen shot, and save to file, easiest way using only one API call A must see

by $mTp (3 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (25 Votes)

This will take a screen shot using only one API call, no bitblt and other complicated routines. This is simple and works. This code will simulate a keypress (the snap shot button), then will copy the data to clipboard (like if you had pressed the Snap shot button on your keyboard) and save it to file. Vote for me or gimme' some feedback if you think this is cool.

Rate Capture desktop/Screen shot, and save to file, easiest way using only one API call A must see

'****Declares

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)


Public Function Capture_Desktop(ByVal Destination$) as Boolean 


On Error goto errl

DoEvents

Call keybd_event(vbKeySnapshot, 1, 0, 0) 'Get the screen and copy it to clipboard

DoEvents 'let computer catch up

SavePicture Clipboard.GetData(vbCFBitmap), Destination$ ' saves the clipboard data to a BMP file

Capture_Desktop = True

Exit Function

errl:

Msgbox "Error number: " & err.number & ". " & err.description

Capture_Desktop = False

End Function
'A lil' example 

Private Sub Command1_Click()

Capture_Desktop "c:\windows\desktop\desktop.bmp" 'That's it

Download this snippet    Add to My Saved Code

Capture desktop/Screen shot, and save to file, easiest way using only one API call A must see Comments

No comments have been posted about Capture desktop/Screen shot, and save to file, easiest way using only one API call A must see. Why not be the first to post a comment about Capture desktop/Screen shot, and save to file, easiest way using only one API call A must see.

Post your comment

Subject:
Message:
0/1000 characters