c++ - 如何将我自己的文件关联添加到 "Open with"上下文菜单中?

标签 c++ winapi wix windows-installer

比如说,如果我右键单击一个文件然后转到“打开方式”菜单,它会显示一个子菜单,类似于这个:

enter image description here

如何将我自己的程序添加到“打开方式”列表中?

附言。请注意,在这种情况下,我不需要创建与特定文件扩展名的关联(用户通常双击打开。)

PS2。从技术上讲,我需要通过 MSI 安装程序(我使用的是 WiX)完成此操作,但如果有人可以建议 API 或注册表进行设置,我也可以通过自定义操作来完成此操作,如果 MSI/WiX 不直接支持它的话。

最佳答案

我想我从 this 中找到了答案和 this文章。

比如说,如果我正在制作一个“Text Zapper”应用程序并想将它关联到“打开方式”.txt 文件。这是 WiX (MSI) 布局的伪标记。它基本上定义了需要设置的注册表项。 (请注意,它没有为应用程序定义 .txt 扩展默认关联。)

<?define ProgId = "Text.Zapper.1" ?>
<?define GuiAppExeName = "txtzpr.exe" ?>
<?define ProductThis = "Text Zapper" ?>
<?define AppDescr = "Wonderful Text Zapper Application" ?>


<Component Id='IdTextZapper' Guid='*'>
  <File Id='IdTextZapperExe' Name='$(var.GuiAppExeName)' DiskId='1' Source='$(var.Srctxtzpr)' KeyPath='yes' />

  <!-- Extend the "open with" Windows Explorer function -->
  <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\$(var.ProgId)" Value="$(var.ProductThis)" Type="string" />
  <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\Applications\$(var.GuiAppExeName)" Name="FriendlyAppName" Value="$(var.ProductThis)" Type="string" />
  <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\Applications\$(var.GuiAppExeName)\shell\open" Name="FriendlyAppName" Value="$(var.ProductThis)" Type="string" />
  <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\Applications\$(var.GuiAppExeName)\shell\open\command" Value='"[INSTALLDIR]$(var.GuiAppExeName)" "%1"' Type="string" />

  <RegistryValue Root="HKLM" Key="SOFTWARE\My Company\Text Zapper\Capabilities" Name="ApplicationDescription" Value="$(var.AppDescr)" Type="string" />
  <RegistryValue Root="HKLM" Key="SOFTWARE\RegisteredApplications" Name="$(var.ProductThis)" Value="SOFTWARE\My Company\Text Zapper\Capabilities" Type="string" />

  <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\.txt\OpenWithProgIDs" Name="$(var.ProgId)" Value="" Type="string" />
  <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\.txt\OpenWithList\$(var.GuiAppExeName)" Value="" Type="string" />
  <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\Applications\$(var.GuiAppExeName)\SupportedTypes" Name=".txt" Value="" Type="string" />
  <RegistryValue Root="HKLM" Key="SOFTWARE\My Company\Text Zapper\Capabilities\FileAssociations" Name=".txt" Value="$(var.ProgId)" Type="string" />

</Component>

关于c++ - 如何将我自己的文件关联添加到 "Open with"上下文菜单中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22831989/

相关文章:

java - 如何将字符串编码为 8 位 ASCII 字符?

api - 挂接到 VBE 窗口的子类 SysTreeView32

Wix安装程序: Write to HKLM/HKCR in per-user installation without elevated rights

windows-services - WIX ServiceInstall - 将服务设置为在 NetworkService 帐户下运行

c++ - 使用 boost::asio 连接到 HTTPS 服务器

c++ - 是否可以将函数导入到命名空间,但不能导出它?

c++ - 如何将空格添加到 concat 预处理器宏?

c++ - 在 C++ 中使用线程

windows - SetErrorMode没有效果?

wix - 微星 : Upgrading 32-Bit application to 64-Bit