VB icon

Capture Screen or Active Window

Email
Submitted on: 1/2/2015 3:01:00 AM
By: Dalin Nie (from psc cd)  
Level: Not Given
User Rating: By 5 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 2527
 
     This function capture the screen or the active window of your computer Programmatically and save it to a .bmp file. This may allows you to get another machine's screen through network!!! Fully tested in VB5.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Capture Screen or Active Window
' Description:This function capture the screen or the active window of your computer
 Programmatically and save it to a .bmp file. This may allows you to get another machine's
 screen through network!!! Fully tested in VB5.
' By: Dalin Nie (from psc cd)
'**************************************

'1: Declare
' This should be in the form's heneral declaration area. 
' If you do it in a module, omit the word "Private"
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
 ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
'
'2. The Function
' You can add this to your form's code
' or you can put it in a module if the declaration is in a module
Public Function fSaveGuiToFile(ByVal theFile As String) As Boolean
' Name: fSaveGuiToFile
' Author: Dalin Nie
' Written: 4/2/99
' Purpose:
' This procedure will Capture the Screen or the active window of your Computer and Save it as 
' a .bmp file
' Input:
' theFile file Name with path, where you want the .bmp to be saved
'
' Output:
' True if successful
'
Dim lString As String
On Error goto Trap
'Check if the File Exist
 If Dir(theFile) <> "" Then Exit Function
 'To get the Entire Screen
 Call keybd_event(vbKeySnapshot, 1, 0, 0)
 'To get the Active Window
 'Call keybd_event(vbKeySnapshot, 0, 0, 0)
 
 SavePicture Clipboard.GetData(vbCFBitmap), theFile
fSaveGuiToFile = True
Exit Function
Trap:
'Error handling
MsgBox "Error Occured in fSaveGuiToFile. Error #: " & Err.Number & ", " & Err.Description
End Function
'
3. To call the function, add the code:
Call fSaveGuiToFile(yourFileNAme)
' Example: in a command1_click event add: call fSaveGuiToFile("C:\Scrn_pic.bmp")
'When you run your app, click command1, the screen will be saved in c:\scrn_pic.bmp.


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.