程序关联实现

类别:Delphi 点击:0 评论:0 推荐:


程序中readme是个.sos文件,点吉它实现如下:

基本实现如下:

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.

本文地址:http://com.8s8s.com/it/it4996.htm