お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"指定のプリンタのプロパティダイアログ表示"





◆解説
  指定のプリンタの「プロパティダイアログ」を表示させる。
  TPrintDialogや TPrinterSetupDialogのダイアログ画面で、
  [プロパティ]ボタンをクリックした時に表示されるダイア
  ログと同じものです。

  用紙サイズや用紙の向き等を設定してから表示できるという
  メリットがあります。

◆動作確認
  Delphi3.1 + Win95a

◆例
  (1) uses に Printers, WinSpool を追加する
  (2) Form1に ListBox1,Button1を置く
----- ここから -----
type
  TForm1 = class(TForm)
    ...省略

implementation

//Form1 OnCreateイベント
procedure TForm1.FormCreate(Sender: TObject);
begin
  ListBox1.Items.Assign(Printer.Printers);
  //通常使うプリンタを選択
  Printer.PrinterIndex := -1;
  ListBox1.ItemIndex := Printer.PrinterIndex;
end;

//Button1 OnClickイベント
procedure TForm1.Button1Click(Sender: TObject);
var
  Device, Driver, Port: array[0..79] of char;
  DeviceMode: THandle;
  DevMode: PDeviceMode;
begin
  if ListBox1.ItemIndex < 0 then begin
    ShowMessage('ListBoxで目的のプリンタを選択して下さい');
    Exit;
  end;

  //ListBox1で選択されたプリンタの「プリンタ名」
  //                        および DEVMODE構造体を取得する
  Printer.PrinterIndex := ListBox1.ItemIndex;
  Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  Printer.SetPrinter(Device, Driver, Port, 0);
  Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  if DeviceMode = 0 then begin
    ShowMessage('Printer.GetPrinter エラー'); Exit;
  end;

  DevMode := GlobalLock(DeviceMode);
  try
    //必要なら、ここで DevModeを修正する
    // B5横 の設定にしてからダイアログを表示する例
    with DevMode^ do begin
      dmPaperSize   := DMPAPER_B5;         //B5
      dmOrientation := DMORIENT_LANDSCAPE; //横
    end;
    DocumentProperties(Application.Handle,
                       0,
                       Device,
                       DevMode^,
                       DevMode^,
                       DM_PROMPT or DM_MODIFY or DM_COPY);
  finally
    GlobalUnlock(DeviceMode);
  end;
end;
----- ここまで -----

  ListBoxで目的のプリンタを選択してから Buttonをクリックして
  下さい。

  必ず[B5横]の設定でダイアログが表示される例です。
  ※B5横に対応していないプリンタの場合には、設定が無視され
    ると思いますが...

Original document by Satobe          氏 ID:(JCG00336)


ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum