tags:

views:

222

answers:

2

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.

+6  A: 

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().
MarkJ
This is good stuff. As you mention, what I actually really needed was something to grab the windows handle other then the desktop. This should do the trick here.As a side note, what I looking to do is screen capture 144 images of a clock with the time pre-set. I going to use VBA to change the system time (via shell), and then do a screen capture of that clock. I could do this manually, but doing an 144 computer time changes, and then having to do a 144 screen captures is quite a bit of work. Those code examples should allow me to automate this process. Thanks again.
Albert D. Kallal
@Albert In that case, I suggest using Spy++ (or one of the free clones) to get the window handle. You click on the window, and they tell you the handle. Here's a list of clones http://stackoverflow.com/questions/1811019/i-want-spy-but-i-dont-have-visual-studio
MarkJ
Golly, I have spy++ installed as part of VS 6, and it gives the handle just fine. (thanks...I don't know why I did not think of this...especially for a one off task).
Albert D. Kallal
A: 

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

Remou
That is a handy routine you have. I actually am not looking to do the clipboard part part in your code. However, I still might use this code. Thank you kindly for that link.
Albert D. Kallal