unit PrnUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, WinSpool;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
 hGlobal  : THandle;
 hPrinter : THandle;
 PD       : TPrinterDefaults;
 PI2      : PPrinterInfo2;
 dwNeeded : DWORD;
begin
 FillChar(PD, SizeOf(PD), 0);
 PD.DesiredAccess := PRINTER_ALL_ACCESS;
 OpenPrinter(PChar('QMS 860 Print System'), hPrinter, @PD);
 GetPrinter(hPrinter, 2, Nil, 0, @dwNeeded);
 hGlobal := GlobalAlloc(GHND, dwNeeded);
 PI2 := PPrinterInfo2(GlobalLock(hGlobal));
 GetPrinter(hPrinter, 2, PI2, dwNeeded, @dwNeeded);
 With Memo1.Lines, PI2^ do
  begin
   If Assigned(pServerName) then
    Add('Server Name = '+pServerName);
   If Assigned(pPrinterName) then
    Add('Printer Name = ' + pPrinterName);
   If Assigned(pDriverName) then
    Add('Driver Name = ' + pDriverName);
   If Assigned(pPortName) then
    Add('Port Name = ' + pPortName);
   with pDevMode^ do
    begin
     If dmOrientation = 1 Then Add('PORTRAIT')
      else Add('LANDSCAPE');
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
 hGlobal  : THandle;
 hPrinter : THandle;
 PD       : TPrinterDefaults;
 PI2      : PPrinterInfo2;
 dwNeeded : DWORD;
begin
 FillChar(PD, SizeOf(PD), 0);
 PD.DesiredAccess := PRINTER_ALL_ACCESS;
 OpenPrinter(PChar('QMS 860 Print System'), hPrinter, @PD);
 GetPrinter(hPrinter, 2, Nil, 0, @dwNeeded);
 hGlobal := GlobalAlloc(GHND, dwNeeded);
 PI2 := PPrinterInfo2(GlobalLock(hGlobal));
 GetPrinter(hPrinter, 2, PI2, dwNeeded, @dwNeeded);
 PI2^.pDevMode^.dmOrientation := DMORIENT_LANDSCAPE;
 SetPrinter(hPrinter, 2, PI2, 0);
 ClosePrinter(hPrinter);
end;

end.
