procedure registerfiletype(ft,key,desc,icon,prg:string);
//ft:文件名后缀,如可以为'.tst'或'afile.tst'
//key:在注册表中的键值,要唯一
//desc:关联程序的描述
//icon:缺省的程序图标,如Application.ExeName+',1',可以缺省
//prg:对应的应用程序
var myreg : treginifile;
ct : integer;
begin // 取文件的后缀
ct := pos('.',ft);
while ct > 0 do begin
delete(ft,ct,1);
ct := pos('.',ft);
end;
if (ft = '') or (prg = '') then exit; //判断后缀及应用程序是否有效
ft := '.'+ft;
myreg := treginifile.create('');
try
myreg.rootkey := hkey_classes_root; // 根应该为HKEY_CLASSES_ROOT
if key = '' then key := copy(ft,2,maxint)+'_auto_file';
// 如果没给出键值,则自动创建一个
myreg.writestring(ft,'',key); // 写入描述的键值
myreg.writestring(key,'',desc); // 写入描述
if icon <> '' then
myreg.writestring(key+'\DefaultIcon','',icon);
// 写入缺省图标
myreg.writestring(key+'\shell\open\command','',prg+' "%1"');
//写入相关联的应用程序
finally
myreg.free;
end;
end;
调用例子:
Example:
registerFileType('.tst',
'testfile',
'测试关联文件',
Application.ExeName+',1',
Application.ExeName);这是从mybase格式的技巧集上复制的,没有验证。
//ft:文件名后缀,如可以为'.tst'或'afile.tst'
//key:在注册表中的键值,要唯一
//desc:关联程序的描述
//icon:缺省的程序图标,如Application.ExeName+',1',可以缺省
//prg:对应的应用程序
var myreg : treginifile;
ct : integer;
begin // 取文件的后缀
ct := pos('.',ft);
while ct > 0 do begin
delete(ft,ct,1);
ct := pos('.',ft);
end;
if (ft = '') or (prg = '') then exit; //判断后缀及应用程序是否有效
ft := '.'+ft;
myreg := treginifile.create('');
try
myreg.rootkey := hkey_classes_root; // 根应该为HKEY_CLASSES_ROOT
if key = '' then key := copy(ft,2,maxint)+'_auto_file';
// 如果没给出键值,则自动创建一个
myreg.writestring(ft,'',key); // 写入描述的键值
myreg.writestring(key,'',desc); // 写入描述
if icon <> '' then
myreg.writestring(key+'\DefaultIcon','',icon);
// 写入缺省图标
myreg.writestring(key+'\shell\open\command','',prg+' "%1"');
//写入相关联的应用程序
finally
myreg.free;
end;
end;
调用例子:
Example:
registerFileType('.tst',
'testfile',
'测试关联文件',
Application.ExeName+',1',
Application.ExeName);这是从mybase格式的技巧集上复制的,没有验证。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货