PDA

Click to See Complete Forum and Search --> : Screenshots


Sep 18th, 2000, 03:15 PM
This will take a picture of the screen.

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

Private Const VK_SNAPSHOT = &H2C


Public Function SaveScreen(ByVal theFile As String) As Boolean
On Error Resume Next

'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

SaveScreen = True
Clipboard.Clear
Exit Function
End Function

Usage:

Call SaveScreen("C:\Windows\Desktop\ss.bmp")

Sep 19th, 2000, 05:33 AM
Thx, but it uses the clipboard, all previous data is lost if you use this code :(

Sep 19th, 2000, 06:25 AM
So copy the previous data to a variable or something and re-copy it.


Public Function SaveScreen(ByVal theFile As String) As Boolean
On Error Resume Next
prevclip = Clipboard.GetText()
'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

SaveScreen = True
Clipboard.Clear
Clipboard.SetText prevclip
Exit Function
End Function

Usage:

Call SaveScreen("C:\Windows\Desktop\ss.bmp")

oetje
Sep 19th, 2000, 12:52 PM
This code copys the screen to Picture1:

Picture1.Autoredraw = True

Dim ScreenDC as long

ScreenDC = GetDC(0&)
BitBlt Picture1.hdc,0,0,1024,768,ScreenDC,0,0,SRCCopy
Picture1.Refresh


Note: 1024=The screenwidth (pixels)
768=The screenheight(pixels)
Don't forget to add the API Declarations, I can't include them, because I don't have VB here.

oetje
Sep 19th, 2000, 12:56 PM
The smiley screwed up the code :-(

Sep 19th, 2000, 01:45 PM
Thx guys, this works :)

ZeroPhill
Oct 19th, 2000, 07:19 AM
Great !!!

It works......
Spezial thanks from Germany......

Quin
Nov 4th, 2001, 08:55 PM
I tried this code

Picture1.Autoredraw = True
Dim ScreenDC as long
ScreenDC = GetDC(0&)
BitBlt Picture1.hdc,0,0,1024,768,ScreenDC,0,0,SRCCopyPicture1.Refresh

I get the error sub or function not declared on GetDC