AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

How can I capture and Print the Screen, a Form, or any Window ?

The included example provides several useful routines for capturing images.
All of the routines have been written to work under both 16- and 32-bit
Windows platforms and they contain full palette support. The routines in
the example can:

- Capture the entire contents of a form.
- Capture the client area of a form.
- Capture the entire screen.
- Capture the active window on the screen.
- Capture any portion of any window given a handle to it.
- Create a Picture object from a bitmap and a palette.
- Print a Picture object as large as possible on the page.

Visual Basic 4.0 introduced a new Picture object. The Picture object is
actually a standard OLE type and it is documented in the Control
Developer's Kit (CDK.)

The CDK includes the function OleCreatePictureIndirect which can be used to
construct new Picture objects from Visual Basic 4.0. The routine
CreateBitmapPicture in the example calls OleCreatePictureIndirect to build
a Picture object from a handle to a bitmap and a handle to a palette. If
the Picture includes a valid palette, Visual Basic will know to use it when
rendering the Picture to the screen or printer. The CreateBitmapPicture
routine is used by the CaptureWindow routine to construct Picture objects
containing a bitmap of a part or all of a window.

The CaptureWindow routine in the example captures any portion of a window
given a window handle. The routine includes several parameters for
describing the exact portion of the window to capture. Capture Window works
by copying the on-screen image of a window into a new bitmap. It also
checks to see if the screen has a palette and if so it makes a copy of it.
CaptureWindow then calls CreateBitmapPicture to construct a bitmap from the
newly created bitmap and palette.

The CaptureForm, CaptureClient, CaptureScreen, and CaptureActiveWindow
routines included in the example all use CaptureWindow to capture specific
windows. CaptureForm and CaptureClient both call Capture window and pass it
the hWnd property of a Form object. CaptureScreen simply gets the handle to
the desk top window and calls CaptureWindow. Similarly, CaptureActiveWindow
just gets the window handle of the active window and calls CaptureWindow.

Once the desired image is captured in a Picture object, it is easy to print
in Visual Basic 4.0 using the PaintPicture method of the Printer object.
The example provides the routine PrintPictureToFitPage that uses the
PaintPictureMethod to print the captured images as large as possible in the
printable area of the page.

View example now.



Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at