お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





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

"指定のプリンタでPrintDialog表示"

この発言に対し以下のコメントが寄せられています
#00618 Satobe さん RE:指定のプリンタでPrintDialog表示

◆解説 TPrintDialog で、指定のプリンタを初期値として表示させる。 【「通常使うプリンタ」でないプリンタ】(ややこしい(^^;) の PrintDialogを表示できます。 ◆動作確認 Delphi3.1 + Win95a ◆例 (1) uses に Printers を追加する (2) Form1に ListBox1,Button1,PrintDialog1を置く ----- ここから ----- type TForm1 = class(TForm) ...省略 private { Private 宣言 } FPrinterName: String; //←追加する ...省略 implementation //Form1 OnCreateイベント procedure TForm1.FormCreate(Sender: TObject); begin ListBox1.Items.Assign(Printer.Printers); //通常使うプリンタを選択 Printer.PrinterIndex := -1; ListBox1.ItemIndex := Printer.PrinterIndex; end; //PrintDialog1 OnShowイベント procedure TForm1.PrintDialog1Show(Sender: TObject); var PNameComboBox: HWND; index: Integer; begin //名前(N)コンボボックスのウィンドウハンドルを取得 PNameComboBox := GetDlgItem(TPrinterSetupDialog(Sender).Handle, $473); if PNameComboBox <> HWND(nil) then begin //コンボボックスのアイテムからFPrinterNameを検索 index := SendMessage(PNameComboBox, CB_FINDSTRING, -1, Longint(PChar(FPrinterName))); if index >= 0 then //FPrinterNameを見つけた SendMessage(PNameComboBox, CB_SETCURSEL, index, 0); end; end; //Button1 OnClickイベント procedure TForm1.Button1Click(Sender: TObject); var Device, Driver, Port: array[0..79] of char; DeviceMode: THandle; begin if ListBox1.ItemIndex < 0 then begin ShowMessage('ListBoxで目的のプリンタを選択して下さい'); Exit; end; //ListBox1で選択されたプリンタの「プリンタ名」を取得する 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; FPrinterName := Device; PrintDialog1.Execute; end; ----- ここまで ----- ListBoxで目的のプリンタを選択してから Buttonをクリックして 下さい。 やってることは TPrinterSetupDialog版とほとんど同じです。 名前(N)コンボボックスのコントロールIDが $473 になっている 程度しか違いがありません。(^^; #カスタムコンポ化してしまった方が便利かも知れませんね。(^^) Original document by Satobe 氏 ID:(JCG00336)



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

Copyright 1996-2002 Delphi Users' Forum