程序关联实现
2006-02-04 13:48:45 来源:WEB开发网基本实现如下:
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('myzip\shell\open\command', true);
//用于打开.sos文件的可执行程序
reg.WriteString('', '"' + application.ExeName + '" "%1"');
reg.CloseKey;
reg.OpenKey('myzip\DefaultIcon',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;
end.
更多精彩
赞助商链接