Author: Mike Shkolnik
How can I receive a current printer settings?
Answer:
At first, you must open the printer device:
1 var
2 FDevice: PChar;
3 FDriver: PChar;
4 FPort: PChar;
5 DeviceMode: THandle;
6 DevMode: PDeviceMode;
7
8 procedure OpenThePrinterDevice;
9 var
10 Driver_Info2: PDriverInfo2;
11 Retrieved: dword;
12 hPrinter: THandle;
13 begin
14 Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
15 if DeviceMode = 0 then
16 Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
17 OpenPrinter(FDevice, hPrinter, nil);
18 GetMem(Driver_Info2, 255);
19 GetPrinterDriver(hPrinter, nil, 2, Driver_info_2, 255, Retrieved);
20 StrLCopy(FDriver, PChar(ExtractFileName(StrPas(Driver_Info2^.PDriverPath))
21 + #0), 63);
22 FreeMem(Driver_info_2, 255);
23 DevMode := GlobalLock(DeviceMode);
24 end;
And now you can get the information from printer. For example, the orientation
settings:
25
26 if ((DevMode^.dmFields and DM_ORIENTATION) = DM_ORIENTATION) and
27 (DevMode^.dmOrientation = DMORIENT_LANDSCAPE) then
28 //Landscape
29 else
30 //Portrait
Also you can detect a paper size, paper source, print duplex and quality etc. View
a const description in Windows.pas.
At last, don't forget to unlock a device:
GlobalUnlock(DeviceMode);
|