Search Tools Links Login

Capture a Certain Window

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


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


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

About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 90 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.