为什么 Windows 7 跳转列表中只显示带有我的文件扩展名的文件?
我正在尝试将我们的应用程序与 Windows 7 跳转列表正确集成。我们允许在应用程序中打开文件,我不久前添加了此内容以将项目添加到跳转列表:
var list = JumpList.CreateJumpList()
list.AddToRecent(file);
list.Refresh();
其中 JumpList 来自 WindowsAPICodePack
这种方法有两个问题。
- 有时,用户会在 Refresh() 调用时收到 ComException(无法删除要替换的文件。(HRESULT 异常:0x80070497))。
- 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 仍然只包含具有我的关联文件扩展名的文件。
我有两个问题:
- 将项目添加到跳转列表的更好方法是什么。
- 如何让任何文件显示在我的跳转列表中,无论文件扩展名如何?
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.
- Occasionally users would get a ComException on the Refresh() call (Unable to remove the file to be replaced. (Exception from HRESULT: 0x80070497)).
- 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:
- What is the better way to add items to the Jump List.
- How do I get any file to show up on my Jump List, regardless of file extension?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 MSDN:
因此,您必须为您关心的每个文件类型添加注册,方法是向 ProgId 添加动词,或者可能只是将您的 ProgId 或 exe 名称添加到 OpenWithProgIds 或 OpenWithList (HKCR\%.ext%\OpenWithProgIds)
Windows 要求这样做的事实有点愚蠢,恕我直言,但我想他们需要知道当您单击跳转列表项时如何将文件路径传递到您的应用程序。
SHAddToRecentDocs 的参数类型比您列出的要多,SHADAPPIDINFOLINK 没有说明您是否需要在任何地方注册才能工作,因此您可以尝试这样做,而不是添加基本路径...
From MSDN:
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...