Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips


#19: How can I get the printer settings?

Today I continue to post a tips for printer settings. At first, you must open the printer device:

At first, you must open the printer device:

var
  FDevice: PChar;
  FDriver: PChar;
  FPort: PChar;
  DeviceMode: THandle;
  DevMode: PDeviceMode;

procedure OpenThePrinterDevice;
var
  Driver_Info2: PDriverInfo2;
  Retrieved: dword;
  hPrinter: THandle;
begin
  Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
  if DeviceMode = 0 then
    Printer().GetPrinter(FDevice, FDriver, FPort, DeviceMode);
  OpenPrinter(FDevice, hPrinter, nil);
  GetMem(Driver_Info2, 255);
  GetPrinterDriver(hPrinter, nil, 2, Driver_info_2, 255, Retrieved);
  StrLCopy(FDriver, PChar(ExtractFileName(StrPas(Driver_Info2^.PDriverPath)) + #0), 63);
  FreeMem(Driver_info_2, 255);
  DevMode := GlobalLock(DeviceMode);
end;

And now you can get the information from printer. For example, the orientation settings:

    if ((DevMode^.dmFields and DM_ORIENTATION) = DM_ORIENTATION) and
       (DevMode^.dmOrientation = DMORIENT_LANDSCAPE) then
      //Landscape
    else
      //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);


Published: August 30, 1999

See also
 
Viewer for TNEF-files (winmail.dat)
Clarion to Text converter
Excel Web-stream
ExcelFile Viewer
Clarion Viewer
ABA Document Convert
Paradox to MS Access converter
Metafile Convert
Paradox Viewer
DBISAM Password Recovery
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2025, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport/SMImport suites