基本實現如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,
Registry,shlobj, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Panel1: TPanel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure reg;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.reg;
var
reg: TRegistry;
begin
reg := TRegistry.Create;
reg.RootKey := HKEY_CLASSES_ROOT;
reg.OpenKey('.sos', true);
reg.WriteString('', 'myzip');
reg.CloseKey;
reg.OpenKey('myzipshellopencommand', true);
//用於打開.sos文件的可執行程序
reg.WriteString('', '"' + application.ExeName + '" "%1"');
reg.CloseKey;
reg.OpenKey('myzipDefaultIcon',true);
//取當前可執行程序的圖標為.sos文件的圖標
reg.WriteString('',''+application.ExeName+',0');
reg.Free;
//立即刷新
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
reg;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
sFile: string;
begin
if ParamCount > 0 then
begin
(* 取得參數內容 *)
sFile := ParamStr(1);
if LowerCase(ExtractFileExt(sFile))='.sos' then memo1.Lines.LoadFromFile(sfile);
end;
end;