function DeleteFileAssociation(Ext:string;Notify:boolean=true):boolean;
var
reg:tregistry;
key:string;
label
final;
begin
result:=false;
key:='';
if ext='' then exit;
if ext[1]<>'.' then ext:='.'+ext;
try
reg:=tregistry.Create;
reg.RootKey:=hkey_classes_root;
if reg.KeyExists(ext) then
begin
if reg.OpenKey(ext,false) then
begin
key:=reg.ReadString('');
reg.CloseKey;
if (not reg.DeleteKey(ext)) or (not reg.DeleteKey(key)) then
goto final;
end
else
goto final;
end;
if notify then
// SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
notifyassociationchange;
result:=true;
final:
finally
reg.Free;
end;
end;
function SetFileAssociation(Ext:string;
OpenApp:string;
FileTypeDescription:string='';
OpenMenuCaption:string='';
IconFile:string='';
IconIndex:integer=0;
Notify:boolean=true):boolean;
var
reg:tregistry;
key:string;
label
final;
begin
result:=false;
if ext='' then exit;
if ext[1]<>'.' then ext:='.'+ext;
if openmenucaption='' then openmenucaption:='&Open';
if IconFile='' then IconFile:=openapp;
key:=copy(ext,2,length(ext))+' File';
if filetypedescription='' then filetypedescription:=key;//////////////////////////////////////////
try
reg:=tregistry.Create;
reg.RootKey:=hkey_classes_root;
if reg.OpenKey(ext,true) then
begin
reg.WriteString('',key);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key,true) then
begin
reg.WriteString('',filetypedescription);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\DefaultIcon',true) then
begin
reg.WriteString('',openapp+','+inttostr(iconindex));
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\Shell\Open',true) then
begin
reg.WriteString('',openmenucaption);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\Shell\Open\Command',true) then
begin
reg.WriteString('','"'+openapp+'" "%1"');
reg.CloseKey;
end
else
goto final;
if notify then
notifyassociationchange;
result:=true;
final:
finally
reg.Free;
end;
end;
procedure NotifyAssociationChange;
begin
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
var
reg:tregistry;
key:string;
label
final;
begin
result:=false;
key:='';
if ext='' then exit;
if ext[1]<>'.' then ext:='.'+ext;
try
reg:=tregistry.Create;
reg.RootKey:=hkey_classes_root;
if reg.KeyExists(ext) then
begin
if reg.OpenKey(ext,false) then
begin
key:=reg.ReadString('');
reg.CloseKey;
if (not reg.DeleteKey(ext)) or (not reg.DeleteKey(key)) then
goto final;
end
else
goto final;
end;
if notify then
// SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
notifyassociationchange;
result:=true;
final:
finally
reg.Free;
end;
end;
function SetFileAssociation(Ext:string;
OpenApp:string;
FileTypeDescription:string='';
OpenMenuCaption:string='';
IconFile:string='';
IconIndex:integer=0;
Notify:boolean=true):boolean;
var
reg:tregistry;
key:string;
label
final;
begin
result:=false;
if ext='' then exit;
if ext[1]<>'.' then ext:='.'+ext;
if openmenucaption='' then openmenucaption:='&Open';
if IconFile='' then IconFile:=openapp;
key:=copy(ext,2,length(ext))+' File';
if filetypedescription='' then filetypedescription:=key;//////////////////////////////////////////
try
reg:=tregistry.Create;
reg.RootKey:=hkey_classes_root;
if reg.OpenKey(ext,true) then
begin
reg.WriteString('',key);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key,true) then
begin
reg.WriteString('',filetypedescription);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\DefaultIcon',true) then
begin
reg.WriteString('',openapp+','+inttostr(iconindex));
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\Shell\Open',true) then
begin
reg.WriteString('',openmenucaption);
reg.CloseKey;
end
else
goto final;
if reg.OpenKey(key+'\Shell\Open\Command',true) then
begin
reg.WriteString('','"'+openapp+'" "%1"');
reg.CloseKey;
end
else
goto final;
if notify then
notifyassociationchange;
result:=true;
final:
finally
reg.Free;
end;
end;
procedure NotifyAssociationChange;
begin
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货