为什么 Windows 7 跳转列表中只显示带有我的文件扩展名的文件?

发布于 2024-10-27 07:32:55 字数 1571 浏览 6 评论 0原文

我正在尝试将我们的应用程序与 Windows 7 跳转列表正确集成。我们允许在应用程序中打开文件,我不久前添加了此内容以将项目添加到跳转列表:

var list = JumpList.CreateJumpList()
list.AddToRecent(file);
list.Refresh();

其中 JumpList 来自 WindowsAPICodePack

这种方法有两个问题。

  1. 有时,用户会在 Refresh() 调用时收到 ComException(无法删除要替换的文件。(HRESULT 异常:0x80070497))。
  2. JumpList 仅包含具有应用程序文件扩展名的文件。

我们允许通过 Open 方法在我们的应用程序中导入其他文件,我希望这些文件也显示在跳转列表中,但它们没有。

我在此处搜索了有关 JumpLists 的问题,并找到了一种不同的方式来添加最近使用的文件 答案

    void AddFileToRecentFilesList(string fileName)
    {
        SHAddToRecentDocs((uint)ShellAddRecentDocs.SHARD_PATHW, fileName);          
    }

    /// <summary>
    /// Native call to add the file to windows' recent file list
    /// </summary>
    /// <param name="uFlags">Always use (uint)ShellAddRecentDocs.SHARD_PATHW</param>
    /// <param name="pv">path to file</param>
    [DllImport("shell32.dll")]
    public static extern void SHAddToRecentDocs(UInt32 uFlags,
        [MarshalAs(UnmanagedType.LPWStr)] String pv);

    enum ShellAddRecentDocs
    {
        SHARD_PIDL = 0x00000001,
        SHARD_PATHA = 0x00000002,
        SHARD_PATHW = 0x00000003
    }

这似乎更合适,因为它还向后兼容 XP、Vista - 问题是 JumpList 仍然只包含具有我的关联文件扩展名的文件。

我有两个问题:

  1. 将项目添加到跳转列表的更好方法是什么。
  2. 如何让任何文件显示在我的跳转列表中,无论文件扩展名如何?

I am trying to properly integrate our app with the Windows 7 Jump Lists. We allow opening files within the application and I added this a while ago to add the items to the jump list:

var list = JumpList.CreateJumpList()
list.AddToRecent(file);
list.Refresh();

where JumpList is from the WindowsAPICodePack

There were two issues with this approach.

  1. Occasionally users would get a ComException on the Refresh() call (Unable to remove the file to be replaced. (Exception from HRESULT: 0x80070497)).
  2. The JumpList would only contain files with the applications file extension.

We allow importing other files in our application via the Open method and I want these files to also show up in the Jump List but they don't.

I searched through the questions regarding JumpLists here on SO and found a different way to add recently used files in this answer:

    void AddFileToRecentFilesList(string fileName)
    {
        SHAddToRecentDocs((uint)ShellAddRecentDocs.SHARD_PATHW, fileName);          
    }

    /// <summary>
    /// Native call to add the file to windows' recent file list
    /// </summary>
    /// <param name="uFlags">Always use (uint)ShellAddRecentDocs.SHARD_PATHW</param>
    /// <param name="pv">path to file</param>
    [DllImport("shell32.dll")]
    public static extern void SHAddToRecentDocs(UInt32 uFlags,
        [MarshalAs(UnmanagedType.LPWStr)] String pv);

    enum ShellAddRecentDocs
    {
        SHARD_PIDL = 0x00000001,
        SHARD_PATHA = 0x00000002,
        SHARD_PATHW = 0x00000003
    }

This seemed more appropriate as it is also backwards compatible with XP, Vista - Problem is that the JumpList still only contains files with my associated file extension.

I have two questions:

  1. What is the better way to add items to the Jump List.
  2. How do I get any file to show up on my Jump List, regardless of file extension?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝情姑娘 2024-11-03 07:32:55

来自 MSDN

应用程序必须是注册的
项目文件类型的处理程序
该类型出现在其跳转列表中。
然而,它并不需要是
该文件类型的默认处理程序

因此,您必须为您关心的每个文件类型添加注册,方法是向 ProgId 添加动词,或者可能只是将您的 ProgId 或 exe 名称添加到 OpenWithProgIds 或 OpenWithList (HKCR\%.ext%\OpenWithProgIds)

Windows 要求这样做的事实有点愚蠢,恕我直言,但我想他们需要知道当您单击跳转列表项时如何将文件路径传递到您的应用程序。

SHAddToRecentDocs 的参数类型比您列出的要多,SHADAPPIDINFOLINK 没有说明您是否需要在任何地方注册才能工作,因此您可以尝试这样做,而不是添加基本路径...

From MSDN:

An application must be a registered
handler for a file type for an item of
that type to appear in its Jump List.
It does not, however, need to be the
default handler for that file type

So you must add register yourself with every filetype you care about, either by adding a verb to the ProgId or possibly just adding your ProgId or exe name to OpenWithProgIds or OpenWithList (HKCR\%.ext%\OpenWithProgIds)

The fact that windows requires this is a bit stupid IMHO, but I guess they need to know how to pass the file path to your app when you click on a jump list item.

SHAddToRecentDocs has more parameter types than you have listed, the docs for SHARDAPPIDINFOLINK does not say if you need to be registered anywhere for it to work so you could try that instead of adding a basic path...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文