简体   繁体   English

如何调用 ShellExecute 使用 C++ 打开具有特定程序的文件而不关联相同的文件扩展名

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

I read MSDN and tried this line of code我阅读了 MSDN 并尝试了这行代码

ShellExecute(handle, "open", "fully_qualified_path_to_file", NULL, NULL, SW_SHOWNORMAL); ShellExecute(handle, "open", "fully_qualified_pa​​th_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.我写了一个应用程序,它在扩展名为 .bin 的文件中输出。 On my OS .bin files doesn't associated with any specific program.在我的操作系统上,.bin 文件与任何特定程序无关。 MSDN says that I can associate all .bin files with my app with programming, but this case is unacceptable for me. MSDN 说我可以将所有 .bin 文件与我的应用程序与编程相关联,但这种情况对我来说是不可接受的。

How I can add this line of code to open specific file with specific program?如何添加这行代码以使用特定程序打开特定文件? ps I tried to put my application path in 4th argument as shown in MSDN, smith like that, ps 我试图将我的应用程序路径放在第 4 个参数中,如 MSDN 所示,就像那样,

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

but it didn't work.但它没有用。

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).如果lpFile参数不是 .exe,则 Windows 只有在注册表中注册了文件类型时才能执行该文件(ShellExecute 将从注册表中读取命令行并将 %1 替换为文件名)。

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.如果要强制使用特定应用程序,则lpFile需要指定所述应用程序的名称/路径,并且您希望它打开的文件必须是应用程序支持的格式的参数的一部分,通常只是应用程序的完整路径文件(如果路径包含空格,则用"引用)。在这种情况下,ShellExecute 不会为您翻译 %1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM