mainunit.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:3k
源码类别:

Delphi/CppBuilder

开发平台:

Delphi

  1. unit mainunit;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, Buttons, ExtCtrls,Registry;
  6. type
  7.   TForm1 = class(TForm)
  8.     GroupBox1: TGroupBox;
  9.     Label1: TLabel;
  10.     Edit1: TEdit;
  11.     Label2: TLabel;
  12.     Edit2: TEdit;
  13.     Label3: TLabel;
  14.     Edit3: TEdit;
  15.     Label4: TLabel;
  16.     Edit4: TEdit;
  17.     Label5: TLabel;
  18.     Edit5: TEdit;
  19.     CheckBox1: TCheckBox;
  20.     BitBtn1: TBitBtn;
  21.     OpenDialog1: TOpenDialog;
  22.     BitBtn2: TBitBtn;
  23.     Image1: TImage;
  24.     Image2: TImage;
  25.     BitBtn3: TBitBtn;
  26.     BitBtn4: TBitBtn;
  27.     procedure FormCreate(Sender: TObject);
  28.     procedure BitBtn1Click(Sender: TObject);
  29.     procedure BitBtn2Click(Sender: TObject);
  30.     procedure BitBtn3Click(Sender: TObject);
  31.     procedure BitBtn4Click(Sender: TObject);
  32.   private
  33.     { Private declarations }
  34.   public
  35.     procedure AddIconToIEExt;
  36.     { Public declarations }
  37.   end;
  38. var
  39.   Form1: TForm1;
  40. implementation
  41. {$R *.dfm}
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. begin
  44.  OpenDialog1.InitialDir:=ExtractFileDir(Application.ExeName);
  45.  OpenDialog1.FileName:='';
  46. end;
  47. procedure TForm1.BitBtn1Click(Sender: TObject);
  48. begin
  49.  With OpenDialog1 do
  50.   begin
  51.    OpenDialog1.FilterIndex:=1;
  52.    OpenDialog1.FileName:='';
  53.    if Execute then
  54.     begin
  55.      if (ExtractFileExt(OpenDialog1.FileName)='.exe') then
  56.       Edit3.Text:=OpenDialog1.FileName;
  57.     end;
  58.   end;
  59. end;
  60. procedure TForm1.BitBtn2Click(Sender: TObject);
  61. begin
  62.  With OpenDialog1 do
  63.   begin
  64.    OpenDialog1.FilterIndex:=2;
  65.    OpenDialog1.FileName:='';
  66.    if Execute then
  67.     begin
  68.      if (ExtractFileExt(OpenDialog1.FileName)='.ico') then
  69.       begin
  70.        Edit4.Text:=OpenDialog1.FileName;
  71.        image1.Picture.LoadFromFile(OpenDialog1.FileName);
  72.       end;
  73.     end;
  74.   end;
  75. end;
  76. procedure TForm1.BitBtn3Click(Sender: TObject);
  77. begin
  78.  With OpenDialog1 do
  79.   begin
  80.    OpenDialog1.FilterIndex:=2;
  81.    OpenDialog1.FileName:='';
  82.    if Execute then
  83.     begin
  84.      if (ExtractFileExt(OpenDialog1.FileName)='.ico') then
  85.       begin
  86.        Edit5.Text:=OpenDialog1.FileName;
  87.        image2.Picture.LoadFromFile(OpenDialog1.FileName);
  88.       end;
  89.     end;
  90.   end;
  91. end;
  92. procedure TForm1.AddIconToIEExt;
  93. var
  94.  Reg:TRegistry;
  95. begin
  96.   Reg:=TRegistry.Create;
  97.   try
  98.    Reg.RootKey:=HKEY_LOCAL_MACHINE;
  99.    if Reg.OpenKey('SoftwareMicrosoftInternet ExplorerExtensions{FB5F1910-F110-11d2-BB9E-00C04F795683}',True)then
  100.      begin
  101.       Reg.WriteString('CLSID','{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}');
  102.       Reg.WriteString('Exec',Edit3.Text);
  103.       Reg.WriteString('HotIcon',Edit4.Text);
  104.       Reg.WriteString('Icon',Edit5.Text);
  105.       Reg.WriteString('ButtonText',Edit1.Text);
  106.       Reg.WriteString('MenuText',Edit2.Text);
  107.       if CheckBox1.Checked then
  108.        Reg.WriteString('Default Visible','Yes')
  109.       else
  110.        Reg.WriteString('Default Visible','No');
  111.      end; 
  112.   finally
  113.    Reg.Closekey;
  114.    Reg.Free;
  115.   end;
  116. end;
  117. procedure TForm1.BitBtn4Click(Sender: TObject);
  118. begin
  119.  if ((Edit1.Text='') or(Edit2.Text='')or
  120.     (Edit3.Text='') or(Edit4.Text='')or (Edit5.Text=''))then
  121.    ShowMessage('请设置好全部参数后,再进行尝试!')
  122.    else
  123.    begin
  124.     AddIconToIEExt;
  125.     ShowMessage('扩展对象信息成功写入注册表!')
  126.    end;
  127. end;
  128. end.
  129. {
  130. ['{7F373309-E50F-4C08-9F78-D1E2AF454DB6}']
  131. {['{1FAD3C6B-666B-4C62-B632-A50E76DF1B70}']  }