unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons,Registry; // 此处加上Registry,才能使程序访问注册表 type TForm1 = class(TForm) A_Check: TCheckBox; B_Check: TCheckBox; Bit_all: TBitBtn; Bit_cancel: TBitBtn; Bit_hide: TBitBtn; GroupBox1: TGroupBox; procedure Bit_allClick(Sender: TObject); procedure Bit_cancelClick(Sender: TObject); procedure Bit_hideClick(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM}
procedure TForm1.Bit_allClick(Sender: TObject); begin a_check.Checked:=true; b_check.Checked:=true; end;
procedure TForm1.Bit_cancelClick(Sender: TObject); begin a_check.Checked:=false; b_check.Checked:=false; end;
procedure TForm1.Bit_hideClick(Sender: TObject); var myreg:TRegistry; temp1,temp2,myval:integer; begin temp1:=0; temp2:=0; myval:=0;
myreg:=TRegistry.Create; with myreg do begin rootkey:=HKEY_LOCAL_MACHINE; if openkey('SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\explorer',true) then begin case form1.A_Check.Checked of true: temp1:=1; end; case form1.B_Check.Checked of true: temp2:=2; end; myval:=temp1+temp2; WriteInteger('NoDrives',myval); myreg.CloseKey; myreg.Free; end; end; end;
procedure TForm1.FormCreate(Sender: TObject); var myreg:TRegistry; begin myreg:=TRegistry.Create; with myreg do begin rootkey:=HKEY_LOCAL_MACHINE; if openkey('SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\explorer',true) and ValueExists('NoDrives') then begin if readinteger('NoDrives')=1 then A_check.Checked:=true; if readinteger('NoDrives')=2 then B_check.Checked:=true; if readinteger('NoDrives')=3 then begin A_check.Checked:=true; B_check.Checked:=true; end; myreg.CloseKey; myreg.Free; end; end; end; end. |