Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Capture Window - Active Window to XYZ.BMP

0.00/5 (No votes)
11 Aug 2005 1  
This article describes how to Capture active window of your application

Introduction

The Capture window is a small application to capture the active window of your application. This program is something I wrote for one of my applications. But by the time I finished it, I thought it might be pretty useful for developers. It can be used to capture the working of the programs.

This project is not complete, it is a work-in-progress. There are numerous issues with the current version which need to be addressed. My long term goal is to develop this to "commercial quality".

I am going to continue to improve this application towards my goal. I will continue to post updates as I feel necessary.

Background

Capture Window is a little program that I wrote when I was having to save win screen during the development of my application Tetris. This program gives a facility to save the window having score with name and quote as a BMP.

Usage

Just run the app. You'll see a screen as shown above. This lets you add your name and quote. Now just click on Save ScreenShot Button. This will generate a BMP file named as "Active Window.BMP".

This article is useful to those of my fellow programmers who are tired of trying to capture the active window to BMP.

Technical Details

Basically we use BitBlt() to get the current window. This usually works better than GetPixel() and SetPixel(). Using this function, we copy active window to Picturebox. Now we use SavePicture to save the active window as BMP.

Using the Code

API Declaration

Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, _
 ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, _ 
 ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Button Event

Private Sub cmdScreenShot_Click()
frmCanvas.PicSaveScreen.Cls
frmCanvas.PicSaveScreen.Height = Me.ScaleHeight + 60
frmCanvas.PicSaveScreen.Width = Me.ScaleWidth + 60

BitBlt frmCanvas.PicSaveScreen.hDC, 0, 0, _
Me.ScaleWidth, Me.ScaleHeight, Me.hDC, 0, 0, vbSrcCopy

SavePicture frmCanvas.PicSaveScreen.Image, App.Path & "\Active Window.BMP"
End Sub

History

  • 12-Aug-2005 - Initial release of article

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here