windows - 如何让Windows根据文件关联打开一个外部文件?

标签 windows winapi file-association

使用特定于 Win32 的 API,是否有一种简单的方法可以通过传入文件的路径/名称来启动外部应用程序来打开文件?

例如,假设我有一个名为 C:\tmp\image.jpg 的文件。我可以调用一个 API 来告诉 Windows 打开与 .jpg 文件关联的应用程序吗?无需进行大量注册表查找?

我想我记得很多年前做过这个,但我找不到了。

最佳答案

ShellExecute

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/

相关文章:

windows - “程序没有响应”是什么意思?

c++ - windows xp本地时间夏令时问题

java - 使用 Java/C++ 使用默认关联程序打开文件

c# - 无法设置图像以使用我的程序打开,为什么不呢?

windows - 从一组 png 图像创建动画 gif

c++ - 如何在 Visual Studio 2019 中有条件编译 C++ 源文件?

c++ - 如何获得鼠标点击的位置(以 x-y 坐标像素为单位)?

c++ - 更改组合框选择的 DateTimePicker 样式失败

delphi - 如何使用 CryptoAPI 加载 OpenSSL 生成的 RSA1024 纯文本公钥?

visual-studio-2008 - Visual Studio 在记事本中打开 .xml 文件