Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
649 views
in Technique[技术] by (71.8m points)

winapi - How to open a default dialog for window if ShellExecute fails due to no file association in C++?

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:

image

Is this possible? If so how?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);

If you check under HKEY_CLASSES_ROOTUnknownshellopenas you see that this is the same as calling the (undocumented) OpenAs_RunDLL export in shell32.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...