1,183
社区成员




unit getprinterpage;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure ComboBox1Select(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses printers,winspool;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
ComboBox1.Items:=Printer.Printers;
ComboBox1.ItemIndex:=1;
end;
procedure TForm1.ComboBox1Select(Sender: TObject);
const
page_name_length = 64;
var
i,p:integer;
pBuf:PChar;
pname:pchar;
begin
pname:=pchar(combobox1.Text);
p:=winspool.DeviceCapabilities(pname,'LPT1',DC_PAPERNAMES,nil,nil);
GetMem(pBuf ,page_name_length *p);
p:=DeviceCapabilities(PName,'LPT1',DC_PAPERNAMES,pBuf,nil);
ComboBox2.clear;
for i:=1 to p do
ComboBox2.Items.Add(pBuf + page_name_length * (i-1));
FreeMem(pBuf);
ComboBox2.ItemIndex:=1;
end;
end.