某扩展名关联某可执行文件,使用下面代码可以实现关联,
function RegAssociatedExec(const AFileExt, AFileType, AFileDescription, AMIMEType, AIcon, AExecName: string): Boolean; stdcall;
begin
Result := False;
if (AFileExt = '') or (AExecName = '') then
Exit;
with TRegistry.Create do
begin
try
RootKey := HKEY_CLASSES_ROOT;
if not OpenKey(AFileExt, True) then
begin
Exit;
end;
WriteString('', AFileType);
if AMIMEType <> '' then
begin
WriteString('Content Type', AMIMEType);
end;
CloseKey;
if not OpenKey(AFileType, True) then
begin
Exit;
end;
WriteString('', AFileDescription);
CloseKey;
if AIcon <> '' then
begin
if not OpenKey(AFileType + '\DefaultIcon', True) then
begin
Exit;
end;
WriteString('', AIcon);
CloseKey;
end;
if not OpenKey(AFileType + '\Shell\Open\Command', True) then
begin
Exit;
end;
WriteString('', AExecName);
CloseKey;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
finally
Free;
end;
end;
end;实现关联以后该扩展名的图标已改变,双击该文件,该可执行文件打开,如何实现可执行文件打开这个文件呢,当然打开文件是自己写的
function RegAssociatedExec(const AFileExt, AFileType, AFileDescription, AMIMEType, AIcon, AExecName: string): Boolean; stdcall;
begin
Result := False;
if (AFileExt = '') or (AExecName = '') then
Exit;
with TRegistry.Create do
begin
try
RootKey := HKEY_CLASSES_ROOT;
if not OpenKey(AFileExt, True) then
begin
Exit;
end;
WriteString('', AFileType);
if AMIMEType <> '' then
begin
WriteString('Content Type', AMIMEType);
end;
CloseKey;
if not OpenKey(AFileType, True) then
begin
Exit;
end;
WriteString('', AFileDescription);
CloseKey;
if AIcon <> '' then
begin
if not OpenKey(AFileType + '\DefaultIcon', True) then
begin
Exit;
end;
WriteString('', AIcon);
CloseKey;
end;
if not OpenKey(AFileType + '\Shell\Open\Command', True) then
begin
Exit;
end;
WriteString('', AExecName);
CloseKey;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
finally
Free;
end;
end;
end;实现关联以后该扩展名的图标已改变,双击该文件,该可执行文件打开,如何实现可执行文件打开这个文件呢,当然打开文件是自己写的
if not OpenKey(AFileType + '\Shell\Open\Command', True) then
begin
Exit;
end;
WriteString('', AExecName);
已经加上了,没啥区别其实
还是没有打开文件,
比如B.ddt文件,想用A.exe打开,执行以上代码后,B.ddt图标已改变,双击B.ddt,A.exe打开,
但没有将B.ddt打开,是不是在软件里还得些代码?
注册表写%1
程序区ParamStr
-----------------------
参考http://www.02t.cn/article/code/2.html
用 ParamStr(1)可以取到,打开就完了。