[対象バージョン]
Delphi 3.0J
[説明]
現在のプリンターの用紙サイズの取得方法と、再設定の方法について。
[対処法]
現在のプリンターの設定状態の取得方法は GetPrinter を使い、再設定は SetPrinter を使います。
[サンプルソース]
uses 章に Printers を追加して下さい。
var DrvName,PrtName,PortName : array[0..127] of char; DeviceMode : THandle; PDevMode : ^TDevMode; begin with Printer do begin GetPrinter ( DrvName, PrtName, PortName, DeviceMode); PDevMode := GlobalLock(DeviceMode); if PDevMode^.dmPaperSize = DMPAPER_A4 then showMessage('A4です。'); if PDevMode^.dmPaperSize = DMPAPER_A3 then showMessage('A3です。'); . . . GlobalUnlock(DeviceMode); end; end;
また プリンター設定の変更も下記のようにすれば行えます。
var DrvName,PrtName,PortName : array[0..127] of char; DeviceMode : THandle; PDevMode : ^TDevMode; begin with Printer do begin // 出力先番号 プリンター、FAXなど (−1はデフォルト) PrinterIndex := -1; GetPrinter ( DrvName, PrtName, PortName, DeviceMode); PDevMode := GlobalLock(DeviceMode); // 用紙サイズ PDevMode^.dmPaperSize := DMPAPER_A3; // 用紙の縦、横の指定 PDevMode^.dmOrientation := DMORIENT_PORTRAIT; GlobalUnlock(DeviceMode); SetPrinter ( DrvName,PrtName,PortName,DeviceMode); end; end;
再設定の内容を使う事で、出力先番号、用紙の縦横の
取得もできます。
出力先名で、出力先を指定したい時は、
Printer.Printers.indexof で指定して下さい。
例) var
printer_no : Integer;
begin
printer_no :=
Printer.Printers.indexof('出力先名');
PrinterIndex := printer_no;
プリンター名を知りたい時は、
Printer.Printers[0]
Printer.Printers[1]
Printer.Printers[2]
.
.
.
プログラムを停止しての内容を見て下さい。
注)QuickReportで使用するときは、QuickReportホームを、
呼ぶ前に指定して下さい、また正常に動かないことが多い様です。
(QuickReportのバグの為)