Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use code to do a screen capture of an application running

Tags:

vba

vb6

ms-access

I need to run some code to capture the window of an application running on the windows desktop (windows XP is fine here).

There are a number of VB6 examples on the web, but they tend to capture the running VB6 application or the desktop only. I am looking for a solution that captures a given window/application. So, I want to be able to supply the name of the application window to capture.

A quick Bing search did result in some code examples, but they captured the desktop or the current running VB6 application. I am willing to modify one of these to capture a given window (named application).

However before I do this, perhaps someone has an link to a vb6 or VBA library code example that will capture/save a given named application window to a bmp or some type of image file on the hard disk.

An link to an VB6 or VBA solution is just fine here. I am willing to modify an existing example.

like image 420
Albert D. Kallal Avatar asked Dec 30 '22 05:12

Albert D. Kallal


2 Answers

You probably already know this, but windows are identified by a unique 4-byte long called the window handle. Any code sample to get a screen capture can do any window: the desktop, the current application, or any running application. You just need to use the right window handle.

Here's some building-blocks:

  1. Find the window handle for an application based on the caption, or part of the caption. Taken from Karl E Peterson's excellent VB6 site. Or here's a Microsoft KnowledgeBase article to do the same thing. EDIT Or for a one-off job like yours, just find it out manually by clicking on the window with a debugging tool like Spy++ or a free clone.
  2. Here's code to get a screen capture of the desktop, from Steve McMahon's excellent vbAccelerator. Just change the code so that it uses the window handle found in step 1, rather than the window handle returned by GetDesktopWindow().
like image 191
MarkJ Avatar answered Jan 10 '23 20:01

MarkJ


I put together some code here to capture an error from Access in another application, as an exercise, it uses windows to do this, so the code may be of use to you: http://forum.lessthandot.com/viewtopic.php?f=95&t=7969#p39648

like image 44
Fionnuala Avatar answered Jan 10 '23 20:01

Fionnuala