扩展名关联可执行文件,可执行文件打开文件
某扩展名关联某可执行文件,使用下面代码可以实现关联,
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);
[解决办法]
对,你要重载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)可以取到,打开就完了。