Click here to Skip to main content
15,884,353 members
Articles / Programming Languages / VBScript

Capture Window - Active Window to XYZ.BMP

Rate me:
Please Sign up or sign in to vote.
3.46/5 (9 votes)
11 Aug 2005CPOL1 min read 52.8K   1.7K   13   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

VB.NET
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

VB.NET
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
Yazeed Hamdan15-Jun-09 5:02
Yazeed Hamdan15-Jun-09 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.