www.pudn.com > IsMenu-v1.4.rar > Unit3.pas, change:2014-06-12,size:7814b


unit Unit3; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, FlatUtils, FlatCtrls, StdCtrls, AdvGlowButton, 
  AdvReflectionLabel, AdvOfficeButtons, EllipsLabel, RzStatus,Registry,shlobj, 
  FileCtrl,ShellApi; 
 
type 
  TForm3 = class(TForm) 
    FlatPanel3: TFlatPanel; 
    progressbar1: TRzProgressStatus; 
    RzLabel7: TEllipsLabel; 
    rzCheckBox2: TAdvOfficeCheckBox; 
    rzCheckBox1: TAdvOfficeCheckBox; 
    FlatPanel4: TFlatPanel; 
    AdvReflectionLabel1: TAdvReflectionLabel; 
    AdvGlowButton1: TAdvGlowButton; 
    RzEdit1: TEdit; 
    FlatGroupBox1: TFlatGroupBox; 
    EllipsLabel1: TEllipsLabel; 
    EllipsLabel2: TEllipsLabel; 
    EllipsLabel3: TEllipsLabel; 
    EllipsLabel4: TEllipsLabel; 
    EllipsLabel5: TEllipsLabel; 
    rzedit2: TEdit; 
    rzedit3: TEdit; 
    rzedit4: TEdit; 
    rzedit5: TEdit; 
    rzedit6: TEdit; 
    AdvGlowButton2: TAdvGlowButton; 
    AdvGlowButton4: TAdvGlowButton; 
    Label1: TLabel; 
    procedure FormShow(Sender: TObject); 
    procedure AdvGlowButton1Click(Sender: TObject); 
    procedure AdvGlowButton2Click(Sender: TObject); 
    procedure AdvGlowButton4Click(Sender: TObject); 
    procedure FlatPanel3MouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
  private 
    { Private declarations } 
  public 
  function SelectFolderDialog(const Handle: integer; const Caption: string; 
const InitFolder: WideString; var SelectedFolder: string): boolean; 
function DeleteDirectory(const DirName: string; const UI: Boolean = False): Boolean; 
    { Public declarations } 
  end; 
 
var 
  Form3: TForm3; 
 
implementation 
 uses Unit2,tsForm; 
{$R *.dfm} 
 
function tform3.SelectFolderDialog(const Handle: integer; const Caption: string; 
const InitFolder: WideString; var SelectedFolder: string): boolean; 
var 
BInfo: _browseinfo; 
Buffer: array[0..MAX_PATH] of Char; 
ID: IShellFolder; 
Eaten, Attribute: Cardinal; 
ItemID: PItemidlist; 
begin 
Result := False; 
BInfo.HwndOwner := Handle; 
BInfo.lpfn := nil; 
BInfo.lpszTitle := Pchar(Caption); 
BInfo.ulFlags := BIF_RETURNONLYFSDIRS + BIF_NEWDIALOGSTYLE; 
SHGetDesktopFolder(ID); 
ID.ParseDisplayName(0, nil, PWideChar(InitFolder), Eaten, ItemID, Attribute); 
BInfo.pidlRoot := ItemID; 
GetMem(BInfo.pszDisplayName, MAX_PATH); 
try 
    if SHGetPathFromIDList(SHBrowseForFolder(BInfo), Buffer) then 
    begin 
      SelectedFolder := Buffer; 
      if Length(SelectedFolder) <> 3 then 
        SelectedFolder := SelectedFolder + '\'; 
      result := True; 
    end 
    else 
    begin 
      SelectedFolder := ''; 
      Result := False; 
    end; 
finally 
    FreeMem(BInfo.pszDisplayName); 
end; 
end; 
 
function CopyDirectory(const Source, Dest: string): boolean; 
var 
fo: TSHFILEOPSTRUCT; 
begin 
FillChar(fo, SizeOf(fo), 0); 
with fo do 
begin 
Wnd := 0; 
wFunc := FO_COPY; 
pFrom := PChar(source+#0); 
pTo := PChar(Dest+#0); 
fFlags := FOF_NOCONFIRMATION+FOF_NOCONFIRMMKDIR ; 
end; 
Result := (SHFileOperation(fo) = 0); 
end; 
 
function tform3.DeleteDirectory(const DirName: string; const UI: Boolean = False): Boolean; 
var 
  fo: TSHFILEOPSTRUCT; 
begin 
  FillChar(fo, SizeOf(fo), 0); 
  with fo do 
  begin 
    Wnd := GetActiveWindow; 
    wFunc := FO_DELETE; 
    pFrom := PChar(DirName + #0); 
    pTo := #0#0; 
    fFlags := FOF_NOCONFIRMATION + FOF_SILENT; 
  end; 
  Result := (SHFileOperation(fo) = 0); 
end; 
 
procedure TForm3.FormShow(Sender: TObject); 
var 
reg:tregistry; 
c:integer; 
n:array[1..5] of string; 
s1,s2:string; 
begin 
 
if p=False then 
begin 
Form1.CheckBox6.Checked:=False; 
Form1.Close; 
end; 
    reg:=tregistry.create; 
    reg.rootkey:=HKEY_CURRENT_USER; 
      if reg.openkey('\software\ismenu',False)then   //如果打开成功 
             begin 
               for c:=1 to 5 do 
               begin 
                   n[c]:=reg.readstring('name'+inttostr(c)); 
               end; 
               sn:=reg.readstring('path'); 
               s2:=reg.ReadString('delete'); 
               if s2='true' then 
               RzCheckBox2.checked:=true 
               else 
               RzCheckBox2.checked:=False; 
             end; 
       if reg.openkey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',False)then 
             begin 
             s1:=reg.readstring('IsMenu');    //readstring()函数读取注册 
             if s1='' then 
             RzCheckBox1.Checked:=False 
             else 
             RzCheckBox1.Checked:=True; 
             end; 
           reg.closekey;     //关闭注册表 
           reg.free;           //释放内存 
      RzEdit1.Text:=sn; 
      RzEdit2.Text:=n[1]; 
      RzEdit3.Text:=n[2]; 
      RzEdit4.Text:=n[3]; 
      RzEdit5.Text:=n[4]; 
      RzEdit6.Text:=n[5]; 
      RzLabel7.Caption:='状态'; 
      progressbar1.Percent:=0; 
end; 
 
procedure TForm3.AdvGlowButton1Click(Sender: TObject); 
var 
  s3:string; 
label 
  loop_start; 
begin 
loop_start: 
if SelectFolderDialog(Handle,'更改快捷方式存放位置','',s3) then 
begin 
if s3='' then 
begin 
ShowMessage('目录无效'); 
RzEdit1.text:=sn; 
goto loop_start; 
end 
else 
begin 
  if ForceDirectories(s3+'\Path1')=False then  //创建文件夹 
      begin 
      ShowMessage('无法在所选位置创建文件、请重新选择位置'); 
      goto loop_start; 
      end 
  else 
  begin 
  DeleteDirectory(s3+'\Path1'); 
  rzEdit1.Text := s3+'IsMenu快捷文件'; 
  end; 
end; 
end; 
end; 
 
procedure TForm3.AdvGlowButton2Click(Sender: TObject); 
var 
reg:tregistry; 
c,n2:integer; 
n:array[1..5] of string; 
s1:string; 
nu:Integer; 
 
begin 
reg:=tregistry.create; 
reg.rootkey:=HKEY_CURRENT_USER; 
if (RzEdit1.Text<>'') and (RzEdit1.Text<>sn) then 
begin 
if CopyDirectory(sn,RzEdit1.text)=true then 
begin 
    ProgressBar1.Percent:=20 ; 
 if DeleteDirectory(sn)=True then 
 begin 
    ProgressBar1.Percent:=40 ; 
    sn:=RzEdit1.Text; 
 end; 
end 
else 
begin 
Exit; 
end; 
if reg.openkey('\software\ismenu',False)then   //如果打开成功 
for nu:=1 to 5 do 
begin 
reg.WriteString('Path'+inttostr(nu),rzedit1.text+'\Path'+inttostr(nu)); 
ProgressBar1.Percent:=40+nu ; 
end; 
reg.WriteString('Path',RzEdit1.text); 
ProgressBar1.Percent:=ProgressBar1.Percent+5 ; 
end; 
ProgressBar1.Percent:=50; 
if reg.OpenKey('\software\ismenu',False) then 
begin 
reg.WriteString('name1',RzEdit2.text); 
reg.WriteString('name2',RzEdit3.text); 
reg.WriteString('name3',RzEdit4.text); 
reg.WriteString('name4',RzEdit5.text); 
reg.WriteString('name5',RzEdit6.text); 
ProgressBar1.Percent:=ProgressBar1.Percent+5; 
form2.RzButton1.Caption:=RzEdit2.text; 
form2.RzButton2.Caption:=RzEdit3.text; 
form2.RzButton3.Caption:=RzEdit4.text; 
form2.RzButton4.Caption:=RzEdit5.text; 
form2.RzButton5.Caption:=RzEdit6.text; 
ProgressBar1.Percent:=ProgressBar1.Percent+5; 
if RzCheckBox2.Checked=True then 
reg.writestring('delete','true') 
else 
reg.writestring('delete','false'); 
ProgressBar1.Percent:=ProgressBar1.Percent+5; 
end; 
 
if reg.openkey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',False)then 
if RzCheckBox1.Checked=True then 
begin 
reg.writestring('IsMenu',ExtractFilePath(Application.ExeName)+ExtractFileName(Application.Exename)); 
 
end 
else 
reg.DeleteValue('IsMenu'); 
 
ProgressBar1.Percent:=ProgressBar1.Percent+5; 
 
           reg.closekey;     //关闭注册表 
           reg.free;           //释放内存 
 
RzLabel7.Font.Color:=clBlue; 
RzLabel7.Caption:='修改成功'; 
form2.Button1.Click; 
form2.RzButton1.Click; 
ProgressBar1.Percent:=100; 
end; 
 
procedure TForm3.AdvGlowButton4Click(Sender: TObject); 
begin 
  Form1.Visible:=True; 
Form2.Visible:=True; 
Form3.Close; 
end; 
 
procedure TForm3.FlatPanel3MouseDown(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
begin 
ReleaseCapture; 
  Perform(WM_SysCommand,$f017,0) 
end; 
 
end.