Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Screen capture


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

'this puts the screen on the clipboard
Call keybd_event(vbKeySnapshot, 1, 0, 0)
DoEvents

'this puts the form on the clipboard
Call keybd_event(vbKeySnapshot, 0, 0, 0)
DoEvents

'use a DoEvents to ensure that the capture is completed before the VB program continues

'to get the image into your program (BMP format)
Picture1.picture = clipboard.getdata(vbCFBitmap)

'to save the image to a file (BMP format)
SavePicture Clipboard.GetData(vbCFBitmap), myFile