線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1171
推到 Plurk!
推到 Facebook!

如何取指定打印机的默认纸张名称

尚未結案
Delhpi
一般會員


發表:9
回覆:14
積分:4
註冊:2008-07-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2011-02-21 21:17:19 IP:124.160.xxx.xxx 訂閱
 
[code delphi]
比如一个打印机,在驱动里把默认纸张修改为A4以外的,比如 US Std Fanfold
现在要取 这个默认的纸张名称


unit Unit1;

interface

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

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

var
Form1: TForm1;

implementation

uses
Printers;

{$R *.dfm}

procedure GetPaperSize;
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
PDMode: PDEVMODE;
begin
Printer.PrinterIndex := Form1.ComboBox1.ItemIndex;

Printer.GetPrinter(Device, Driver, Port, hDMode);
Printer.SetPrinter(Device, Driver, Port, 0);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
try
if pDMode <> nil then
begin
Form1.Memo1.Lines.Add(Inttostr(pDMode^.dmPaperSize));//这个值 是正确的
Form1.Memo1.Lines.Add(pDMode^.dmFormName);//这个值不对,每次都是A4
end;
finally
GlobalUnlock(hDMode);
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
GetPaperSize;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Assign(Printer.Printers);
end;

end.

[/code]
系統時間:2024-03-28 16:34:44
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!