|
|
|
Writing BMP and PCX files
Frank Schoonjans (frank.schoonjans@ugent.be)
For Stony Brook Modula-2
The aim of this library is to provide a simple interface to save the contents of a window as a BMP or PCX file.
The download bitmapfiles.zip
contains te modules BitmapFiles.def, BitmapFiles.mod, PCXFiles.def, PCXFiles.mod and a general file input/output module FIO.def and FIO.mod. This FIO module basically is a Windows file API wrapper.
Your comments are appreciated.
The interface of the library, in BitmapFiles.def, exist of only one procedure SaveWindowAsBitmap:
DEFINITION MODULE BitmapFiles;
(* Frank Schoonjans
http://www.modula2.org
Module to save a Windows content as a BMP or PCX file *)
FROM WIN32 IMPORT HWND,HDC;
FROM SYSTEM IMPORT CAST;
TYPE WindowDrawProcedure = PROCEDURE (HWND,HDC);
CONST NIL_WindowDrawProcedure = CAST(WindowDrawProcedure,NIL);
PROCEDURE SaveWindowAsBitmap(type : INTEGER; (* 0=BMP; 1=PCX *)
hWnd : HWND;
drawproc : WindowDrawProcedure;
filename : ARRAY OF CHAR;
bmwidth,bmheight : INTEGER) : INTEGER;
(* Saves the contents of a window as BMP or PCX file;
If no drawing routine is supplied (drawproc=NIL_WindowDrawProcedure)
then the parameters bmwidth and bmheight are ignored.
The drawing routine typically is the same procedure as the one called
after receiving the windows WM_PAINT message.
Returns
0 = OK
1 = Cannot create image file.
(Win API CreateCompatibleBitmap failed).
Lower the image width and height.
2 = No memory
3 = Cannot create file
9 = Other error (probably not enough memory)
*)
END BitmapFiles. |
There are 2 methods to call the library.
Method 1
If you do not provide a drawing procedure of type WindowDrawProcedure, and you use
the constant NIL_WindowDrawProcedure for this parameter,
then the contents of the window's client area will be exported as it is displayed on the screen.
result:=SaveWindowAsBitmap(0,hwnd,NIL_WindowDrawProcedure,
"c:\test.bmp",0,0);
|
The width and height (in pixels) of the bitmap will be the width and height of the client area,
and the parameters bmwidth and bmheight will be ignored.
This method requires that the window is not being overlapped by any other window (including dialog boxes).
Method 2
But maybe you want a BMP or PCX file with a different resolution (width and height)
than the window displayed. In this case you have to provide a drawing procedure.
PROCEDURE DrawClientArea(hwnd; HWND; hdc : HDC);
BEGIN
(* some code to draw the window's client rectangle
on the device context hdc *)
END DrawClientArea;
|
You can then call our routine as follows:
result:=SaveWindowAsBitmap(0,hwnd,DrawClientArea,
"c:\test.bmp",800,600);
|
| |