unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Printers,
Dialogs, FR_Class, StdCtrls, winspool, LMDCustomComboBox,
LMDPrinterComboBox;
type
TForm1 = class(TForm)
frReport1: TfrReport;
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
LMDPrinterComboBox1: TLMDPrinterComboBox;
procedure Button1Click(Sender: TObject);
procedure LMDPrinterComboBox1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Papers: Array[0..255] of Word;
PaperSizes: Array[0..255] of TPoint;
procedure GetPaperName;
end;
Type
TPName = array[0..63] of char;
TPNames = array[0..0] of TPName;
var
Form1: TForm1;
ADevice, ADriver, APort: PChar;
DeviceMode: THandle;
FMode: PDeviceMode;
implementation
{$R *.dfm}
procedure TForm1.GetPaperName;
var
i,j:integer;
PaperName: Pointer;
begin
i:= DeviceCapabilities(ADevice, APort, DC_PAPERNAMES, nil,nil);
if i>1 then
GetMem(PaperName, i*64)
else
exit;
DeviceCapabilities(ADevice, APort, DC_PAPERNAMES, PaperName, nil);
FillChar(Papers, SizeOf(Papers), #0);
DeviceCapabilities(ADevice, APort, DC_PAPERS, @PaperSizes, FMode);
DeviceCapabilities(ADevice, APort, DC_PAPERS, @Papers, FMode);
Memo2.Lines.Clear;
for j:=0 to i-1 do
begin
Memo2.Lines.Add(StrPas(TPNames(PaperName^)[j])+' ==> '+IntToStr(Papers[j]));
end;
FreeMem(PaperName, i*64);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetMem(ADevice, 128);
GetMem(ADriver, 128);
GetMem(APort, 128);
FillChar(ADevice^, 128, 0);
FillChar(ADriver^, 128, 0);
FillChar(APort^, 128, 0);
Printer.GetPrinter (ADevice, ADriver, APort, DeviceMode );
FMode := GlobalLock(DeviceMode);
Memo1.Lines.Assign(Printer.Printers);
Memo1.Lines.Add('===================================');
Memo1.Lines.Add('打 印 机:' + Printer.Printers[Printer.PrinterIndex]);
Memo1.Lines.Add('纸张的物理尺寸:' + IntToStr(GetDeviceCaps(Printer.Handle, PHYSICALWIDTH))+' X '+IntToStr(GetDeviceCaps(Printer.Handle, PHYSICALHEIGHT)));
Memo1.Lines.Add('可打印区域:' + IntToStr(GetDeviceCaps(Printer.Handle, HORZRES))+' X '+IntToStr(GetDeviceCaps(Printer.Handle, VERTRES)));
Memo1.Lines.Add('横向偏移量:' + IntToStr(GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX)));
Memo1.Lines.Add('纵向偏移量:' + IntToStr(GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY)));
GetPaperName;
FreeMem(ADevice, 128);
FreeMem(ADriver, 128);
FreeMem(APort, 128);
end;
procedure TForm1.LMDPrinterComboBox1Change(Sender: TObject);
begin
Printer.PrinterIndex := LMDPrinterComboBox1.ItemIndex;
end;
end.