如果 ShellExecute 由于 C++ 中没有文件关联而失败,如何打开窗口的默认对话框? [英] How to open a default dialog for window if ShellExecute fails due to no file association in C++?
本文介绍了如果 ShellExecute 由于 C++ 中没有文件关联而失败,如何打开窗口的默认对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只要文件关联正确,我就可以使用 Windows ShellExecute 函数打开文件而不会出现问题.
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?
推荐答案
The documented way to show that dialog is to use the openas verb.
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED|COINIT_DISABLE_OLE1DDE);
SHELLEXECUTEINFO sei = { sizeof(sei) };
sei.fMask = SEE_MASK_NOASYNC;
sei.nShow = SW_SHOWNORMAL;
sei.lpVerb = "openas";
sei.lpFile = "C:\\yourfile.ext";
ShellExecuteEx(&sei);
如果您在 HKEY_CLASSES_ROOT\Unknown\shell\openas
下检查,您会发现这与在 shell32 中调用(未记录的)OpenAs_RunDLL 导出相同.
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.
这篇关于如果 ShellExecute 由于 C++ 中没有文件关联而失败,如何打开窗口的默认对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文