Узнать версию драйвера принтера 2
Оформил: DeeCo
Автор: http://www.swissdelphicenter.ch
{ Another Code by P. Below }
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, WinSpool;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private-Deklarationen }
pEnumDriversData: PDriverInfo2;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ListBox1Click(Sender: TObject);
var
pTemp: PDriverInfo2;
begin
with Sender as TListbox do
begin
if ItemIndex >= 0 then
begin
memo1.Clear;
pTemp := PDriverInfo2(Items.Objects[ItemIndex]);
with memo1.Lines, pTemp^ do
begin
Add(Format('cVersion:'#9#9'%d' , [cVersion]));
Add(Format('pName:'#9#9'%s' , [pName]));
Add(Format('pEnvironment:'#9'%s' , [pEnvironment]));
Add(Format('pDriverPath:'#9'%s' , [pDriverPath]));
Add(Format('pDataFile:'#9#9'%s' , [pDataFile]));
Add(Format('pConfigFile:'#9'%s' , [pConfigFile]));
end;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i, bytesNeeded: DWORD;
pTemp: PDriverInfo2;
NumDrivers: DWORD;
begin
listbox1.Clear;
if Assigned(pEnumDriversData) then
FreeMem(pEnumDriversData);
// get number of installed drivers
Numdrivers := 0;
bytesNeeded := 0;
EnumPrinterDrivers(nil, nil, 2, nil, 0, bytesNeeded, NumDrivers);
if bytesNeeded = 0 then
begin
ShowMessage('No printer drivers installed!');
Exit;
end;
// allocate memory for the driver data
GetMem(pEnumDriversData, bytesNeeded);
// fetch driver data
if EnumPrinterDrivers(nil, nil, 2, pEnumDriversData, bytesNeeded,
bytesNeeded, NumDrivers) then
begin
// add drivers to listbox1
pTemp := pEnumDriversData;
for i := 1 to Numdrivers do
begin
listbox1.Items.AddObject(pTemp^.pName, TObject(pTemp));
Inc(pTemp);
// Note: Inc increments a pointer by the size of its base type!
end;
listbox1.ItemIndex := 0;
listbox1Click(listbox1);
end
else
RaiseLastWin32Error;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(pEnumDriversData) then
FreeMem(pEnumDriversData);
end;
end.
|