如何显示“打开”未注册文件扩展名的对话框? [英] How can I display the "open with" dialog for an unregistered file extension?

查看:195
本文介绍了如何显示“打开”未注册文件扩展名的对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让用户为当前未注册的文件扩展名选择一个关联(打开方式)。

I want to let the user select an association (open with) for an currently unregistered file extension.

目前我正在告诉API将文件打开使用 ShellExecute 并返回 ERROR_NO_ASSOCIATION 错误代码。

Currently I'm telling the API to open the file by using ShellExecute and it returns an ERROR_NO_ASSOCIATION error code.

有没有办法告诉API它应该让用户选择一个新的关联?

Is there a way to tell the API that it should let the user select a new association?

推荐答案

我使用

procedure ShellOpenAs(const AFileName: string; AHandle: HWND);
begin
  ShellExecute(AHandle, 'open', PChar('rundll32.exe'), PChar('shell32.dll,OpenAs_RunDLL ' + AFileName), nil, SW_SHOWNORMAL);
end;

修改(灵感来自于David的评论, http://stackoverflow.com/a/13229516/1431618 ):
一个可以省略 ShellExecute RunDll32 通过调用 OpenAs_RunDLL 直接:

Edit (inspired by David's comment and http://stackoverflow.com/a/13229516/1431618): One can omit ShellExecute and RunDll32 by calling OpenAs_RunDLL directly:

procedure OpenAs_RunDLL(hwnd: HWND; hinst: HINST; lpszCmdLine: LPSTR; nCmdShow: Integer); stdcall; external shell32;

procedure ShellOpenAs(AHandle: HWND; const AFileName: string);
begin
  OpenAs_RunDLL(AHandle, HInstance, PChar(AFileName), SW_SHOWNORMAL);
end;

还有一个 SHOpenWithDialog 。 (我觉得有趣的是,Microsoft写了一个RunDLL兼容的入口点,但直到Vista没有打扰提供一个常规的API函数。)

There is also SHOpenWithDialog on Windows Vista and later. (I find it interesting that Microsoft wrote a RunDLL compatible entry point but until Vista didn't bother to provide a regular API function.)

这篇关于如何显示“打开”未注册文件扩展名的对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆