Scalabium Software

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

#20: How can I set a printer settings?

The next part of the tip for printer settings.

At first, of course, you must open the printer device (as I described in previous tip " to get a printer settings").

Now you can set the any settings (supported only, of course) in properties of DevMode^ variable and add a "assigned" flag in DevMode^.dmFields. After that you need call a SetPrinter procedure and unlock device.

View small example:

procedure SetPrinterSettings(FPrinter: TPrinter);
  FDevice: PChar;
  FDriver: PChar;
  FPort: PChar;
  DeviceMode: THandle;
  DevMode: PDeviceMode;
  {to get a current printer settings}
  FPrinter.GetPrinter(FDevice, FDriver, FPort, DeviceMode);
  {lock a printer device}
  DevMode := GlobalLock(DeviceMode);

  {set a paper size as A4-Transverse}
  if ((DevMode^.dmFields and DM_PAPERSIZE) = DM_PAPERSIZE) then
    DevMode^.dmFields := DevMode^.dmFields or DM_PAPERSIZE;
    DevMode^.dmPaperSize := DMPAPER_A4_TRANSVERSE;

  {set a paper source as Tractor bin}
  if  ((DevMode^.dmFields and DM_DEFAULTSOURCE) = DM_DEFAULTSOURCE) then
    DevMode^.dmFields := DevMode^.dmFields or DM_DEFAULTSOURCE;
    DevMode^.dmDefaultSource := DMBIN_TRACTOR;

  {set a Landscape orientation}
  if  ((DevMode^.dmFields and DM_ORIENTATION) = DM_ORIENTATION) then
    DevMode^.dmFields := DevMode^.dmFields or DM_ORIENTATION;
    DevMode^.dmOrientation := DMORIENT_LANDSCAPE;

  {set a printer settings}
  FPrinter.SetPrinter(FDevice, FDriver, FPort, DeviceMode);

  {unlock a device}

Published: September 1, 1999

See also
ExcelFile Viewer
dBase Viewer
Paradox Viewer
Viewer for TNEF-files (winmail.dat)
Paradox to Text converter
Excel Reader (dll)
ABA Database Convert
SMExport suite
ABA Spreadsheet Convert

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2017, Scalabium Software. All rights reserved.

SMExport/SMImport suites