getting the whole desktop
VB Code:
Option Explicit
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 KEYEVENTF_KEYUP = &H2
Private Function SaveFormPic() As Picture
Dim pic As StdPicture
Set pic = Clipboard.GetData(vbCFBitmap)
DoEvents
keybd_event vbKeySnapshot, 1, 0, 0
DoEvents
Set SaveFormPic = Clipboard.GetData(vbCFBitmap)
Clipboard.SetData pic, vbCFBitmap
End Function
Private Sub Command1_Click()
SavePicture SaveFormPic, "C:\MyPic.jpg" 'picture location
End Sub
hey guys, the above code works fine but only grabs the active window, how can i make it grab the desktop, thanks!
Re: getting the whole desktop
you may try the link in my signature. it grabs the whole desktop, but i made it for a specific post, you may need to experiment and change the code according to your need.
Harsh Gupta
Re: getting the whole desktop
thanks harsh but the bmp is far too big, nearly 3mb
Re: getting the whole desktop
Try this
VB Code:
Option Explicit
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
Private Function SaveScreen(ByVal theFile As String) As Boolean
'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
End Function
Private Sub Command1_Click()
Call SaveScreen("d:\shot1.bmp")
End Sub
Re: getting the whole desktop
Quote:
Originally Posted by Pouncer
thanks harsh but the bmp is far too big, nearly 3mb
yes, it because BMPs do have large file size. you may need some good JPG encoder class to convert it to encode it to small size, because VB does not create JPG files.
you may search here to find one good JPG encoder thing, i dont remember exactly who posted it, but that was a good thing from Planet-source-code. so you may search PSC also.
Harsh Gupta.