比如说,如果我右键单击一个文件然后转到“打开方式”菜单,它会显示一个子菜单,类似于这个:
如何将我自己的程序添加到“打开方式”列表中?
附言。请注意,在这种情况下,我不需要创建与特定文件扩展名的关联(用户通常双击打开。)
PS2。从技术上讲,我需要通过 MSI 安装程序(我使用的是 WiX)完成此操作,但如果有人可以建议 API 或注册表进行设置,我也可以通过自定义操作来完成此操作,如果 MSI/WiX 不直接支持它的话。
最佳答案
比如说,如果我正在制作一个“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/