VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Capture a Certain Window

by �e7eN (23 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This will capture the specified window and paste it into a picturebox. Really Simple and easy to follow. Please Vote and Comment!

Inputs
Just add a Picturebox to a form and use the line CaptureWindow hWnd, PictureBox eg. CaptureWindow Me.hWnd, Picture1

Rate Capture a Certain Window

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

Download this snippet    Add to My Saved Code

Capture a Certain Window Comments

No comments have been posted about Capture a Certain Window. Why not be the first to post a comment about Capture a Certain Window.

Post your comment

Subject:
Message:
0/1000 characters