扩展名关联可执行文件,可执行文件打开文件

xiaowei_001 2013-01-28 04:32:07
某扩展名关联某可执行文件,使用下面代码可以实现关联,


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;



实现关联以后该扩展名的图标已改变,双击该文件,该可执行文件打开,如何实现可执行文件打开这个文件呢,当然打开文件是自己写的
...全文
441 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
OO_is_just_P 2013-01-29
  • 打赏
  • 举报
回复
双击后 注册表写的%1会作为参数传入程序。 用 ParamStr(1)可以取到,打开就完了。
OO_is_just_P 2013-01-29
  • 打赏
  • 举报
回复
这儿的writestring的内容改为 “AExecName+‘ %1’” 注册表写%1 程序区ParamStr ----------------------- 参考http://www.02t.cn/article/code/2.html
hsfzxjy 2013-01-28
  • 打赏
  • 举报
回复
引用 4 楼 xiaowei_001 的回复:
to 3 已经加上了,没啥区别其实 还是没有打开文件, 比如B.ddt文件,想用A.exe打开,执行以上代码后,B.ddt图标已改变,双击B.ddt,A.exe打开, 但没有将B.ddt打开,是不是在软件里还得些代码?
对,你要重载WM_DROPFILES消息,这个消息是当有文件拖拽到程序界面上或是有关联文件启动本程序时接收到的,参考($DELPHI)\DEMO\RichEdit这个工程,这是一个仿Windows写字板,里面有这个类似操作,着重看TMainForm的WMDropFiles,POpen,FormShow三个过程。
xiaowei_001 2013-01-28
  • 打赏
  • 举报
回复
to 3 已经加上了,没啥区别其实 还是没有打开文件, 比如B.ddt文件,想用A.exe打开,执行以上代码后,B.ddt图标已改变,双击B.ddt,A.exe打开, 但没有将B.ddt打开,是不是在软件里还得些代码?
jaxdong 2013-01-28
  • 打赏
  • 举报
回复
这儿的writestring的内容改为 “AExecName+‘ %1’”
if not OpenKey(AFileType + '\Shell\Open\Command', True) then
      begin
        Exit;
      end;
      WriteString('', AExecName);
xiaowei_001 2013-01-28
  • 打赏
  • 举报
回复
1楼审题不清啊 后面还有问题呢,
「已注销」 2013-01-28
  • 打赏
  • 举报
回复
感谢分享 呵呵

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧