Capture a Certain Window
![Visual Basic 6, or VB Classic Visual Basic 6, or VB Classic](https://www.fortypoundhead.com//assets/img/icons/v7/vb6.png)
This will capture the specified window and paste it into a picturebox. Really Simple and easy to follow. Please Vote and Comment!
Original Author: ?še7eN
Inputs
Just add a Picturebox to a form and use the line
CaptureWindow hWnd, PictureBox
eg. CaptureWindow Me.hWnd, Picture1
Code
Private Declare Function BitBlt Lib "GDI32" (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, ByVal XSrc As Long, ByVal YSrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Sub CaptureWindow(WindowhWnd As Long, Output As PictureBox)
Dim Ret As Long
Dim WindowRect As RECT
Dim WindowhWnd As Long
Dim nHeight As Long, nWidth As Long
Output.Cls 'Clear the picturebox
Ret = GetWindowRect(WindowhWnd, WindowRect) 'Get the windows co-ordinates
nWidth = WindowRect.Right - WindowRect.Left 'Get the windows Width
nHeight = WindowRect.Bottom - WindowRect.Top ' Get the windows height
Ret = BitBlt(Output.hDC, 0, 0, nWidth, nHeight, GetWindowDC(WindowhWnd), 0, 0, vbSrcCopy)'Get the windows image and copy it to the Picturebox
End Sub
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.