开发者

Why do only files with my file extension show up in the Windows 7 jump list?

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 开发者_StackOverflow中文版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?


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜