I finally have been able to run my routine without an error.
It adds the form with the correct name but not with the correct sizes.
The spec says the width and height should be in thousands of millimeters.
No matter what numbers I use, from 0 to 200000, the width and height in the added form shows as 11099.62in.
Any ideas on what's going on?
I have not found any BAP sample programs that show how to use a BAP structure within another BAP structure.
I may be doing this wrong but I don't know any other method.
Here is my code:
Code: Select all
/*
BOOL AddForm(
_In_ HANDLE hPrinter,
_In_ DWORD Level,
_In_ LPBYTE pForm
);
The FORM_INFO_1 structure contains information about a print form.
The information includes the print form's origin, its name,
its dimensions, and the dimensions of its printable area.
Syntax
C++
typedef struct _FORM_INFO_1 {
DWORD Flags;
LPTSTR pName;
SIZEL Size;
RECTL ImageableArea;
} FORM_INFO_1, *PFORM_INFO_1;
Members
Flags
The form properties. The following values are defined.
Value Meaning
FORM_USER If this bit flag is set, the form has been defined by the user.
Forms with this flag set are defined in the registry.
FORM_BUILTIN If this bit-flag is set, the form is part of the spooler.
Form definitions with this flag set do not appear in the registry.
FORM_PRINTER If this bit flag is set, the form is associated with a certain
printer, and its definition appears in the registry.
pName
Pointer to a null-terminated string that specifies the name of the form.
The form name cannot exceed 31 characters.
Size
The width and height, in thousandths of millimeters, of the form.
ImageableArea
The width and height, in thousandths of millimeters, of the form.
Requirements
Printing
Print Spooler API Structures
AddForm
GetForm
SetForm
*/
#INCLUDE "dcdialog.CH"
#INCLUDE "dll.CH"
#INCLUDE "bap.CH"
#define FORM_USER 0
#define FORM_BUILTIN 1
#define FORM_PRINTER 2
STATIC snHdll
FUNCTION Main()
LOCAL cPrinterName := 'Epson ESC/P-R', ;
cFormName := 'RogerTestForm'
x := PrinterAddForm( cPrinterName, cFormName, 200, 250 )
? x
wait
RETURN nil
* -----------
FUNCTION SizeStructure( nWidth, nHeight )
LOCAL aBin := BaInit(2), cBin
BaStruct( aBin, nWidth ) // Width
BaStruct( aBin, nHeight ) // height
cBin := BaAccess(aBin)
RETURN cBin
* -----------
FUNCTION FormStructure( nFlags, cFormName, sSize, sRect )
LOCAL aBin := BaInit(4), cBin
cFormName := Pad(cFormName+Chr(0),31)
BaStruct( aBin, nFlags ) // Flags
BaStruct( aBin, @cFormName ) // Name
BaStruct( aBin, @sSize ) // SIZEL
BaStruct( aBin, @sRect ) // RECTL
cBin := BaAccess(aBin)
RETURN cBin
* -------------
FUNCTION PrinterAddForm( cPrinterName, cFormName, nWidth, nHeight )
LOCAL sSize, sRect, nFlags, hPrinter := 0, sForm, nLevel := 1
sSize := SizeStructure( nWidth, nHeight )
sRect := SizeStructure( nWidth, nHeight )
nFlags := FORM_USER + FORM_PRINTER
sForm := FormStructure( nFlags, cFormName, @sSize, @sRect )
x := OpenPrinterA( cPrinterName, @hPrinter, nil )
wtf x, hPrinter
IF hPrinter > 0
RETURN AddFormA( hPrinter, nLevel, sForm )
ENDIF
RETURN -1
* -------------
DLLFUNCTION AddFormA( hPrinter, nLevel, @sForm ) USING STDCALL FROM WINSPOOL.DRV
DLLFUNCTION OpenPrinterA( cPrinterName, @hPrinter, sDefaults ) USING STDCALL FROM WINSPOOL.DRV