如果 ShellExecute 由于 C++ 中没有文件关联而失败,如何打开窗口的默认对话框?
我可以使用 Windows ShellExecute 函数打开一个文件,只要该文件具有正确的关联,就不会出现任何问题。
如果不存在关联,我想使用默认的 Windows 对话框打开文件:
这可能吗?如果是这样怎么办?
I can use the windows ShellExecute function to open a file with no problems so long as the file has a correct association.
If no association exists i would like to use the default windows dialog to open the file:
Is this possible? If so how?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
记录 方式 显示该对话框是使用 openas动词。
如果您在
HKEY_CLASSES_ROOT\Unknown\shell\openas
下进行检查,您会发现这与在 shell32 中调用(未记录的)OpenAs_RunDLL 导出相同。The documented way to show that dialog is to use the openas verb.
If you check under
HKEY_CLASSES_ROOT\Unknown\shell\openas
you see that this is the same as calling the (undocumented) OpenAs_RunDLL export in shell32.执行
RUNDLL32 Shell32,OpenAs_RunDLL path/to/file/to/open
Execute
RUNDLL32 Shell32,OpenAs_RunDLL path/to/file/to/open
只是不要使用明确的动词。使用像“open”这样的特定动词是一个很大的错误:
它是一个更正确的方式是简单地将 NULL 作为动词传递。系统将自动选择最合适的动词:
换句话说,simple
将显示“打开方式”对话框。
仅当您想要特定操作时才使用特定动词。例如“打印”、“探索”、“运行”。否则 - 只需传递 nil。
Simply do not use explicit verb. Using a specific verb like 'open' is a big mistake:
It is a way more correct to simply pass NULL as verb. The system will automatically select most appropriate verb:
In other words, simple
will show "Open with" dialog.
Only use a specific verb if you want a specific action. E.g. 'print', 'explore', 'runas'. Otherwise - just pass nil.