Click here to Skip to main content
Click here to Skip to main content

Capture Window - Active Window to XYZ.BMP

, 11 Aug 2005
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

parinit
Web Developer
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 1 PinmemberYazeed Hamdan15-Jun-09 5:02 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.1 | Last Updated 11 Aug 2005
Article Copyright 2005 by parinit
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid