Réponse acceptée !
Tu devrais trouver ton bonheur la dedans :
Commentaire de
salimdz2004 le 20/04/2007 03:23:57
j'ai modifier le programme mnt il marche avec la Base de Registre
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Inifiles;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure Liste_Imprimante(Destino : TStrings);
procedure Selectionne_Imprimante(Imprimante : String);
implementation
uses Registry;
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//
end;
procedure Liste_Imprimante(Destino : TStrings);
var
RegCode : TRegistry;
Str : String;
vtCount, i : Integer;
begin
Destino.Clear;
RegCode := TRegistry.Create;
try
RegCode.RootKey := HKEY_CURRENT_USER;
if RegCode.OpenKey('Software\Microsoft\Windows NT\CurrentVersion\Devices',False)
then RegCode.GetValueNames(Destino);
finally
RegCode.CloseKey;
RegCode.Free;
end;
end;
procedure Selectionne_Imprimante(Imprimante : String);
var
RegCode : TRegistry;
Str, Str1 : String;
Arr_Tmp : Array[0..64] of Char;
vtCount, i : Integer;
begin
RegCode := TRegistry.Create;
try
RegCode.RootKey := HKEY_CURRENT_USER;
if RegCode.OpenKey('Software\Microsoft\Windows NT\CurrentVersion\Devices',False)
then begin
if RegCode.ValueExists(Imprimante)
then begin
Str1 := RegCode.ReadString(Imprimante);
Str := Imprimante + ',' + Str1;
RegCode.CloseKey;
RegCode.RootKey := HKEY_CURRENT_USER;
if RegCode.OpenKey('Software\Microsoft\Windows NT\CurrentVersion\Windows',False)
then begin
if RegCode.ValueExists('Device')
then RegCode.WriteString('Device',Str);
//Windows Refresh changes :
StrCopy(Arr_Tmp, 'windows');
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@Arr_Tmp));
end;
end;
end;
finally
RegCode.CloseKey;
RegCode.Free;
end;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
Liste_Imprimante(ListBox1.Items);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
if (ListBox1.ItemIndex <> -1)
then Selectionne_Imprimante(ListBox1.Items[ListBox1.ItemIndex]);
end;
end.