procedure TForm1.Button2Click(Sender: TObject);
var
hPrinter: THandle;
Device :
array[0..255]
of char;
Driver :
array[0..255]
of char;
Port :
array[0..255]
of char;
hDeviceMode: THandle;
pDevmodeOut: PDeviceMode;
bytesNeeded: DWORD;
begin
Printer.PrinterIndex := combobox1.itemindex;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
if WinSpool.OpenPrinter(@Device, hPrinter,
nil)
then
try
bytesNeeded := DocumentProperties(
handle, hPrinter, Device,
Nil,
Nil, 0 );
pDevmodeOut := AllocMem( bytesNeeded );
If IDOK = DocumentProperties(
Handle, hPrinter, Device, pDevModeOut,
Nil,
DM_OUT_BUFFER
or DM_IN_PROMPT )
Then
;
// do something intelligent here
FreeMem( pDevModeOut );
finally
WinSpool.ClosePrinter( hPrinter );
end;
end;