我如何获取打印机默认的纸张的类型,A4,A5,B5,A3.等等(100分)

  • 主题发起人 主题发起人 jesseyzy
  • 开始时间 开始时间
J

jesseyzy

Unregistered / Unconfirmed
GUEST, unregistred user!
我如何获取打印机默认的纸张的类型,A4,A5,B5,A3.等等
用代码实现
 
procedure TForm1.Button1Click(Sender: TObject);
var
Device: Array[0..(cchDeviceName -1)] of char;
Driver: Array[0..(MAX_PATH -1)] of char;
Port: Array[0..32] of char;
HDMode : THandle;
PDMode: PDevMode;
begin
Printer.PrinterIndex := Printer.PrinterIndex ;
Printer.GetPrinter(Device, Driver, Port, HDMode);
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode <> nil then
begin
case pDMode.dmPaperSize of
DMPAPER_USER: ShowMessage('纸张类型:自定义');
DMPAPER_A3: ShowMessage('纸张类型:A3');
DMPAPER_A4: ShowMessage('纸张类型:A4');
DMPAPER_A5: ShowMessage('纸张类型:A5');
DMPAPER_B4: ShowMessage('纸张类型:B4');
DMPAPER_B5: ShowMessage('纸张类型:B5');
else
ShowMessage('纸张类型:其它');
end;
GlobalUnLock(HDMode);
Printer.PrinterIndex := Printer.PrinterIndex;
end;
end;
end;
 
我用了不了啊,到
这句老出错
Printer.PrinterIndex := Printer.PrinterIndex ;
 
晕!你不会没有uses Printers吧?
 
nnd你才没有uses Printers列,
 
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Inifiles,Printers, ExtCtrls, QuickRpt;
procedure TForm1.Button3Click(Sender: TObject);
var
Device: Array[0..(cchDeviceName -1)] of char;
Driver: Array[0..(MAX_PATH -1)] of char;
Port: Array[0..32] of char;
HDMode : THandle;
PDMode: PDevMode;
printer :Tprinter;
begin
showmessage('111111');
Printer.PrinterIndex := Printer.PrinterIndex ;
showmessage('2222');
Printer.GetPrinter(Device,Driver,Port,HDMode);
showmessage('2222');
showmessage(inttostr(hdmode)) ;
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
// showmessage(inttostr(PDMode)) ;
if PDMode <> nil then
begin
case pDMode.dmPaperSize of
DMPAPER_USER: showmessage('纸张类型:自定义');
DMPAPER_A3: showmessage('纸张类型:A3');
DMPAPER_A4: showmessage('纸张类型:A4');
DMPAPER_A5: showmessage('纸张类型:A5');
DMPAPER_B4: showmessage('纸张类型:B4');

DMPAPER_B5: showmessage('纸张类型:B5');

else
showmessage('纸张类型:其它');
end;

GlobalUnLock(HDMode);

Printer.PrinterIndex := Printer.PrinterIndex;
end;


end;

end;

我用了不了啊,到
这句老出错
Printer.PrinterIndex := Printer.PrinterIndex ;
 
我这里测试一切正常啊?我是Delphi 7.0的
 
我能否加你的qq?我的25826507, 我发截图给你看
我的也是d7 啊
 
你报什么错?Printer是Printers里定义的一个函数:
TPrinter = class(TObject)
private
FCanvas: TCanvas;
FFonts: TStrings;
FPageNumber: Integer;
FPrinters: TStrings;
FPrinterIndex: Integer;
FTitle: string;
FPrinting: Boolean;
FAborted: Boolean;
FCapabilities: TPrinterCapabilities;
State: TPrinterState;
DC: HDC;
DevMode: PDeviceMode;
DeviceMode: THandle;
FPrinterHandle: THandle;
procedure SetState(Value: TPrinterState);
function GetCanvas: TCanvas;
function GetNumCopies: Integer;
function GetFonts: TStrings;
function GetHandle: HDC;
function GetOrientation: TPrinterOrientation;
function GetPageHeight: Integer;
function GetPageWidth: Integer;
function GetPrinterIndex: Integer;
procedure SetPrinterCapabilities(Value: Integer);
procedure SetPrinterIndex(Value: Integer);
function GetPrinters: TStrings;
procedure SetNumCopies(Value: Integer);
procedure SetOrientation(Value: TPrinterOrientation);
procedure SetToDefaultPrinter;
procedure CheckPrinting(Value: Boolean);
procedure FreePrinters;
procedure FreeFonts;
public
constructor Create;
destructor Destroy;
override;
procedure Abort;
procedure begin
Doc;
procedure EndDoc;
procedure NewPage;
procedure GetPrinter(ADevice, ADriver, APort: PChar;
var ADeviceMode: THandle);
procedure SetPrinter(ADevice, ADriver, APort: PChar;
ADeviceMode: THandle);
procedure Refresh;
property Aborted: Boolean read FAborted;
property Canvas: TCanvas read GetCanvas;
property Capabilities: TPrinterCapabilities read FCapabilities;
property Copies: Integer read GetNumCopies write SetNumCopies;
property Fonts: TStrings read GetFonts;
property Handle: HDC read GetHandle;
property Orientation: TPrinterOrientation read GetOrientation write SetOrientation;
property PageHeight: Integer read GetPageHeight;
property PageWidth: Integer read GetPageWidth;
property PageNumber: Integer read FPageNumber;
property PrinterIndex: Integer read GetPrinterIndex write SetPrinterIndex;
property Printing: Boolean read FPrinting;
property Printers: TStrings read GetPrinters;
property Title: string read FTitle write FTitle;
end;

function Printer: TPrinter;
function Printer: TPrinter;
begin
if FPrinter = nil then
FPrinter := TPrinter.Create;
Result := FPrinter;
end;
你检查一下看看,还有你别的地方是否定义过变量恰好名为Printer?
 
property PrinterIndex: Integer read GetPrinterIndex write SetPrinterIndex;
晕倒太多e文了,我怎么打给你啊,我把这句Printer.PrinterIndex := Printer.PrinterIndex ;
给注释了,就可以运行了,但返回showmessage('纸张类型:其它');
而我定义的纸张是A4啊
 
你如果只有一个打印机就先改为Printer.PrinterIndex := 0;试试
 
我对应的修改为Printer.PrinterIndex := 0
提示错误
 
高手我能否加你的qq??
我的qq是25826507
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
StdCtrls, ComCtrls, ExtCtrls, Printers, Dialogs;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Device: array[0..(cchDeviceName -1)] of Char;
Driver: array[0..(MAX_PATH -1)] of Char;
Port: array[0..32] of Char;
HDMode: THandle;
PDMode: PDevMode;
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, HDMode);
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode <> nil then
begin
case pDMode.dmPaperSize of
DMPAPER_USER: ShowMessage('纸张类型:自定义');
DMPAPER_A3: ShowMessage('纸张类型:A3');
DMPAPER_A4: ShowMessage('纸张类型:A4');
DMPAPER_A5: ShowMessage('纸张类型:A5');
DMPAPER_B4: ShowMessage('纸张类型:B4');
DMPAPER_B5: ShowMessage('纸张类型:B5');
else
ShowMessage('纸张类型:其它');
end;
GlobalUnLock(HDMode);
Printer.PrinterIndex := Printer.PrinterIndex;
end;
end;
end;

end.
这是我的测试的全部代码,没有任何问题,我跟踪过Printer.PrinterIndex := Printer.PrinterIndex;这句,得到的PrinterIndex为0,所以改为Printer.PrinterIndex := 0;也是可以的。
 
把你的全部代码贴上来看看。
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Inifiles,Printers, ExtCtrls, QuickRpt;
type
TForm1 = class(TForm)
FontDialog1: TFontDialog;
PrintDialog1: TPrintDialog;
PrinterSetupDialog1: TPrinterSetupDialog;
PageSetupDialog1: TPageSetupDialog;
Button3: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label4: TLabel;
QuickRep1: TQuickRep;
procedure Button3Click(Sender: TObject);

private
{ Private declarations }

public
{ Public declarations }

end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
var
Device: Array[0..(cchDeviceName -1)] of char;
Driver: Array[0..(MAX_PATH -1)] of char;
Port: Array[0..32] of char;
HDMode : THandle;
PDMode: PDevMode;
printer :Tprinter;
begin
showmessage(inttostr(printer.PrinterIndex ));

Printer.PrinterIndex := Printer.PrinterIndex ;
// Printer.PrinterIndex := 0;
Printer.GetPrinter(Device,Driver,Port,HDMode);
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode <> nil then
begin
case pDMode.dmPaperSize of
DMPAPER_USER: showmessage('纸张类型:自定义');
DMPAPER_A3: showmessage('纸张类型:A3');
DMPAPER_A4: showmessage('纸张类型:A4');
DMPAPER_A5: showmessage('纸张类型:A5');
DMPAPER_B4: showmessage('纸张类型:B4');

DMPAPER_B5: showmessage('纸张类型:B5');

else
showmessage('纸张类型:其它');
end;

GlobalUnLock(HDMode);
Printer.PrinterIndex := Printer.PrinterIndex;
// Printer.PrinterIndex := 0;
end;

end;

end;

end.
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,Inifiles,Printers, ExtCtrls, QuickRpt;
type
TForm1 = class(TForm)
Button3: TButton;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
var
Device: Array[0..(cchDeviceName -1)] of char;
Driver: Array[0..(MAX_PATH -1)] of char;
Port: Array[0..32] of char;
HDMode : THandle;
PDMode: PDevMode;
printer :Tprinter;
begin
Printer.PrinterIndex := Printer.PrinterIndex ;
Printer.GetPrinter(Device,Driver,Port,HDMode);
if HDMode <> 0 then
begin
PDMode := GlobalLock(HDMode);
if PDMode <> nil then
begin
case pDMode.dmPaperSize of
DMPAPER_USER: showmessage('纸张类型:自定义');
DMPAPER_A3: showmessage('纸张类型:A3');
DMPAPER_A4: showmessage('纸张类型:A4');
DMPAPER_A5: showmessage('纸张类型:A5');
DMPAPER_B4: showmessage('纸张类型:B4');

DMPAPER_B5: showmessage('纸张类型:B5');

else
showmessage('纸张类型:其它');
end;

GlobalUnLock(HDMode);
Printer.PrinterIndex := Printer.PrinterIndex;
end;

end;

end;

end.

这个是就一个button的,但是没有任何提示啊,
 
var
Device: Array[0..(cchDeviceName -1)] of char;
Driver: Array[0..(MAX_PATH -1)] of char;
Port: Array[0..32] of char;
HDMode : THandle;
PDMode: PDevMode;
printer :Tprinter;
printer :Tprinter;这个定义去掉
 
不好意思。怎么把有的默认的纸张类型加入到一个bombobox
哈哈
帮我解决,我帮你在加100分
 
后退
顶部