} } }

    XP 之后, Delphi 动注册表不便利了...逼出来一个办法:

    添加时间:2013-7-10 点击量:


    手头的法度须要批改注册表, 以让当前法度成为某格局的默认打开法度并接洽关系图标; Vista 之后须要经管员权限才干操纵注册表, 很麻烦, 所以有了下面的测验测验.




    unit Unit1;

    interface

    uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

    type
    TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;

    var
    Form1: TForm1;

    implementation

    {¥R .dfm}

    uses System.IOUtils, Winapi.ShellAPI, Winapi.ShlObj; //RegApp 函数用到的单位

    //接洽关系默认法度的函数
    procedure RegApp(const aExt, aAppName, aAppPath: string);
    const
    nRegFmt = Windows Registry Editor Version 5.00 + sLineBreak +
    [HKEY_CLASSES_ROOT\%0:s] + sLineBreak +
    @=%1:s + sLineBreak +
    [HKEY_CLASSES_ROOT\%1:s\DefaultIcon] + sLineBreak +
    @=%2:s,0 + sLineBreak +
    [HKEY_CLASSES_ROOT\%1:s\shell] + sLineBreak +
    [HKEY_CLASSES_ROOT\%1:s\shell\open] + sLineBreak +
    [HKEY_CLASSES_ROOT\%1:s\shell\open\command] + sLineBreak +
    @=%3:s;
    var
    RegStr: string;
    str3, str4: string;
    RegTmpFile: string;
    begin
    str3 := aAppPath.Replace(\, \\);
    str4 := Format(%s %%1, [str3]).Replace(, \);
    RegStr := Format(nRegFmt, [aExt, aAppName, str3, str4]);
    RegTmpFile := TPath.GetTempPath + RegTmp.reg;
    with TStringList.Create do begin
    Text := RegStr;
    SaveToFile(RegTmpFile);
    Free;
    end;
    Shellute(0, nil, PChar(RegTmpFile), nil, nil, SW_SHOWNORMAL);
    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil); //刷新图标显示
    end;


    procedure TForm1.FormCreate(Sender: TObject);
    var
    S: string;
    begin
    S := ParamStr(1);
    if FileExists(S) then Memo1.Lines.LoadFromFile(S);
    end;

    //履行注册函数; 履行后, 可随便批改一个文本文件的后缀为 tst, 然后双击测试
    procedure TForm1.Button1Click(Sender: TObject);
    begin
    RegApp(.tst, MyApp1, Application.ExeName); //假定法度名称是 MyApp1, 要打开的文件的后缀是 .tst
    end;

    end.

    我俩之间有着强烈的吸引力。短短几个小时后,我俩已经明白:我们的心是一个整体的两半,我俩的心灵是孪生兄妹,是知己。她让我感到更有活力,更完美,更幸福。即使她不在我身边,我依然还是感到幸福,因为她总是以这样或者那样的方式出现在我心头。——恩里克·巴里奥斯《爱的文明》
    分享到: