|
-
Mar 9th, 2002, 04:29 PM
#1
Thread Starter
Frenzied Member
Grabing The Desktop And Putting It In A Picture Box
hello people i want to grab the screen and put it in a picture box how can i do this? if found some things but they dont work
i want it to be captured on a button click name of the button GRAB and picturebox = picturegrab
this is on of the files i found
code:--------------------------------------------------------------------------------
Declare Function BitBlt Lib "gdi32" _
(ByVal hDestDC As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal nWidth As Integer, _
ByVal nHeight As Integer, ByVal _
hSrcDC As Integer, ByVal xSrc As Integer, _
ByVal ySrc As Integer, ByVal dwRop As _
Long) As Integer
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetDC Lib "user32" _
(ByVal hwnd As Long) As Long
Sub Grabscreen(Dest As PictureBox)
Dim DeskhWnd As Long, DeskDC As Long
'Get the hWnd of the desktop
DeskhWnd = GetDesktopWindow()
'BitBlt needs the DC to copy the image. So, we
'need the GetDC API.
DeskDC = GetDC(DeskhWnd)
Dest.AutoRedraw = True
BitBlt Dest.hDC, 0, 0, _
Screen.Width / Screen.TwipsPerPixelX, Screen.Height / Screen.TwipsPerPixelY, DeskDC, _
0, 0, vbSrcCopy
Dest.Refresh
End Sub
-
Mar 9th, 2002, 04:43 PM
#2
VB Code:
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
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
End Function
Private Sub Command1_Click()
Call SaveScreen("C:\Program Files\shot1.bmp")
Picture1.Picture = LoadPicture("C:\Program Files\shot1.bmp")
End Sub
-
Mar 9th, 2002, 04:46 PM
#3
Thread Starter
Frenzied Member
OK but i dont want to save it to file but bring it to a picture box :S
-
Mar 9th, 2002, 04:49 PM
#4
Thread Starter
Frenzied Member
oh doh... but is there a way to make it direct instead of letting it save first and then load? cant i set it to the box imediatly?
-
Mar 9th, 2002, 04:50 PM
#5
Thread Starter
Frenzied Member
OK fixed this myself.. but eer.. it only grabs the current form.. not the entire desktop
-
Mar 9th, 2002, 04:53 PM
#6
Thread Starter
Frenzied Member
this is the code 
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() 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)
picture1.Picture = Clipboard.GetData(vbCFBitmap)
SaveScreen = True
End Function
Private Sub Command1_Click()
Call SaveScreen
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|