首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

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

2013-02-17 
扩展名关联可执行文件,可执行文件打开文件某扩展名关联某可执行文件,使用下面代码可以实现关联,function R

扩展名关联可执行文件,可执行文件打开文件
   某扩展名关联某可执行文件,使用下面代码可以实现关联,


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;



实现关联以后该扩展名的图标已改变,双击该文件,该可执行文件打开,如何实现可执行文件打开这个文件呢,当然打开文件是自己写的
[解决办法]
感谢分享        呵呵
[解决办法]
这儿的writestring的内容改为 “AExecName+‘ %1’”
if not OpenKey(AFileType + '\Shell\Open\Command', True) then
      begin
        Exit;
      end;
      WriteString('', AExecName);

[解决办法]
引用:
to 3
已经加上了,没啥区别其实
还是没有打开文件,


比如B.ddt文件,想用A.exe打开,执行以上代码后,B.ddt图标已改变,双击B.ddt,A.exe打开,
但没有将B.ddt打开,是不是在软件里还得些代码?


对,你要重载WM_DROPFILES消息,这个消息是当有文件拖拽到程序界面上或是有关联文件启动本程序时接收到的,参考($DELPHI)\DEMO\RichEdit这个工程,这是一个仿Windows写字板,里面有这个类似操作,着重看TMainForm的WMDropFiles,POpen,FormShow三个过程。
[解决办法]
这儿的writestring的内容改为 “AExecName+‘ %1’”
注册表写%1
程序区ParamStr
-----------------------
参考http://www.02t.cn/article/code/2.html
[解决办法]
双击后 注册表写的%1会作为参数传入程序。
用 ParamStr(1)可以取到,打开就完了。

热点排行