如何在不关联相同文件扩展名的情况下调用ShellExecute以使用C ++使用特定程序打开文件 [英] How to call ShellExecute to open a file with specific program using C++ without associating same file extensions

查看:53
本文介绍了如何在不关联相同文件扩展名的情况下调用ShellExecute以使用C ++使用特定程序打开文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了MSDN并尝试了这一行代码

I read MSDN and tried this line of code

ShellExecute(句柄,打开",完全限定路径的文件",NULL,NULL,SW_SHOWNORMAL);

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

它工作正常,但我需要更多功能.我写了一个应用程序,使文件扩展名为.bin.在我的操作系统上,.bin文件没有与任何特定程序关联.MSDN表示我可以通过编程将所有.bin文件与我的应用程序相关联,但是这种情况对我来说是不可接受的.

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.

如何添加此行代码以使用特定程序打开特定文件?p.s.我试图将我的应用程序路径放在MSDN所示的第4个参数中,史密斯就是这样,

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"

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

但是没有用.

推荐答案

如果 lpFile 参数不是.exe,则Windows仅在文件类型已注册的情况下才能执行该文件.在注册表中(ShellExecute将从注册表中读取命令行,并将%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).

如果您要强制使用特定的应用程序,则 lpFile 需要指定该应用程序的名称/路径,并且您要打开的文件必须是受以下参数支持的格式的一部分参数:应用程序,通常只是文件的完整路径(如果路径包含空格,则用"引用).在这种情况下,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.

这篇关于如何在不关联相同文件扩展名的情况下调用ShellExecute以使用C ++使用特定程序打开文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆