使用特定于 Win32 的 API,是否有一种简单的方法可以通过传入文件的路径/名称来启动外部应用程序来打开文件?
例如,假设我有一个名为 C:\tmp\image.jpg 的文件。我可以调用一个 API 来告诉 Windows 打开与 .jpg 文件关联的应用程序吗?无需进行大量注册表查找?
我想我记得很多年前做过这个,但我找不到了。
最佳答案
Performs an operation on a specified file.
Syntax
C++
HINSTANCE ShellExecute( _In_opt_ HWND hwnd, _In_opt_ LPCTSTR lpOperation, _In_ LPCTSTR lpFile, _In_opt_ LPCTSTR lpParameters, _In_opt_ LPCTSTR lpDirectory, _In_ INT nShowCmd );
Parameters
...
nShowCmd [in]
Type: INT
The flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it. These values are defined in Winuser.h...
关于windows - 如何让Windows根据文件关联打开一个外部文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/367141/