Capture of Windows to Image Files

The capture of displayed windows to image files can be done by any number of avaialble utility programs, including the use of the Alt-PrintScreen mechanism of Windows 9x itself. The grab.exe command line utility is still another capture program that is adapted for use with Tcl/Tk scripts.

Installing the program

Download the grab 1.0 archive. Uncompress it in a directory that is in your current path (for example, the \windows directory). The program is now ready to run from a command prompt.

Command format

The general format of the command line call to this application is:

grab -c -h -l -p -r -w -t title -f name -d value

where the options have the following uses:

-c Places the output on the clipboard
-h Displays a help message
-l Produces a list of the windows that can be captured
-r Specifies that child windows should be included
-w Specifies that both client and non client window regions should be captured
-t Specified the window title of the target window
-f Specifies a file name for the captured image
-d Specifies a color depth for the captured image (1,4,8 or 24)
-p Causes the target window to pop up to the top the display stack

Clearly, some parameters are exclusive of others. Specifying -c will send the output to the clipboard, so a file name is not required. Similarly, the -l option does not result in any capture, but produces a list of the captureable windows on standard output in Tcl list format.

The default color depth for capture is that of the current display device. If you wish to reduce the color depth to some smaller value than your default, then the -d parameter can be used. The color space reduction is done by dithering, so the result may not be entirely pleasing to the eye if the colors used in the captured window are not similar to those used in standard palettes for the associated depths. Note that is rarely makes sense to use this option to inflate the color depth.

Using the Program with Tcl

Within a Tcl script, you can get the list of windows of interest using a command like the following:

set list [exec grab -l -r]

which will set list to a list of all visible, non-iconic windows with non-empty titles. Because the -r option is specified, the list actually contains a list of lists. Each element of the list consists of a list of 2 elements, the first of which is the title of the top level window and the second of which is a list of the titles of the child windows of that top level window.

If the -r option is not specified, the resulting list is a list of elements that are the titles of the top level windows currently visible.

Examples

The grab.tcl script that is supplied with the distribution is a wish script that demonstrates how the grab.exe program could be used to capture windows. After grab.exe is properly installed, start the demonstration script with a command like:

wish83 -f grab.tcl

The following screen images have been captured using the program:

The above image was captured at default color resolution to the Windows clipboard, then pasted into this document. The Grab application displays the list of grabable top level windows in the listbox. To grab a window, just double click on the name of the window to capture.

In the above case, the window grabbed was the Grab application, so the "Automatically hide..." option is not checked. If you want to grab a full screen window, then check this option first.

Checking the "Recurse child windows" option will change the list of windows to include any children of the top level windows that can be captured. Where child windows are captured, you may grab just the client area of the child or the entire window, including its border and title. Checking the "Capture entire window" option will enable the latter mode.

The "Capture to clipboard" option sends the output to the WIndows clipboard in Device Independant Bitmap (DIB) format. Unchecking this option will enable the file name entry widget, and the output will be saved in a disk file as a Windows DIB.

The color depth entry widget can be used to specify the color depth, in bits per pixel, or the output image. The default value of -1 captures the image at the color resolution of your screen. Other possible values are 8, 4 or 1. The following image was captured at 4 bits of color resolution:

while the following image was captured at 1 bit of color resolution:

As you may observe, the effects of dithering the image to lower color resolutions has a degrading effect on the image, although, for some images, such as the following one at 4 bits, the results can be useful: