How to call ShellExecute to open a file with specific program using C++ without associating same file extensions

懵懂的女人 提交于 2021-02-05 12:38:46

问题


I read MSDN and tried this line of code

ShellExecute(handle, "open", "fully_qualified_path_to_file", NULL, NULL, SW_SHOWNORMAL);

It works fine, but I need some more functionality. I wrote an app, which makes output in file with .bin extension. On my OS .bin files doesn't associated with any specific program. MSDN says that I can associate all .bin files with my app with programming, but this case is unacceptable for me.

How I can add this line of code to open specific file with specific program? p.s. I tried to put my application path in 4th argument as shown in MSDN, smith like that,

C:\\Application.exe" "%1"

but it didn't work.


回答1:


If the lpFile parameter is not a .exe then Windows will only be able to execute the file if it has a file type registration in the registry (ShellExecute will read the command line from the registry and replace %1 with the filename).

If you want to force a specific application then lpFile needs to specify the name/path of said application and the file you want it to open has to be part of the parameters in a format supported by the application, usually just the full path to the file (quoted with " if the path contains spaces). ShellExecute will not translate %1 for you in this case.



来源:https://stackoverflow.com/questions/47215280/how-to-call-shellexecute-to-open-a-file-with-specific-program-using-c-without

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!