问题
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