SHAddToRecentDocs 没有文件?

发布于 2024-08-26 16:57:36 字数 348 浏览 8 评论 0原文

我正在研究一个 IRC 客户端,将其与 Windows 7 应用栏集成。

要获取“频繁”或“最近”项目列表,必须调用 SHAddToRecentDocs API。 我想将最近访问的 IRC 频道添加到 IRC 应用程序的 Windows 7 跳转列表中。 现在,我的问题是,文件系统中不存在 IRC 频道。 SHAddToRecentDocs 似乎坚持获取某种文件系统对象。

我尝试通过创建指向我的应用程序的 IShellItem 并为其提供启动通道的命令行来解决此问题。然而 shell 正在反叛,到目前为止还没有明显地将我的任何“最近文档”尝试添加到跳转列表中。

有没有办法在不创建某种完全不需要的文件系统对象的情况下做到这一点?

I was toying with an IRC client, integrating it with the windows 7 app bar.

To get a "Frequent" or "Recent" items list one has to call SHAddToRecentDocs API.
I want to add recent IRC channels visited to the Windows 7 Jumplist for the IRC application.
Now, my problem is, IRC channels don't exist in the file system. And SHAddToRecentDocs seems to insist on getting some sort of file system object.

Ive tried to work around it by creating a IShellItem pointing to my application, and giving it a command line to launch the channel. The shell is rebelling however, and thus far has not visibly added any of my "recent document" attempts to the Jumplist.

Is there no way to do this without creating some kind of entirely unwanted filesystem object?

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

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

发布评论

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

评论(1

晨曦慕雪 2024-09-02 16:57:36

问题 1671793 完成了一部分。您需要一个 IShellLink 而不是 IShellItem。我一点一点地尝试了该代码。在使用 IPropertyStore 设置标题之前,一切都无法进行。 IPersistFile 代码似乎没有必要。

综上所述,虽然现在当我右键单击应用程序的任务栏图标时会出现一些项目,但我还没有将它们作为我的应用程序的子菜单显示在开始菜单上(例如,像 word 文档那样) ),所以我还不太满意。我认为这是 SHAddToRecentDocs 文档中警告的结果:

可执行 (.exe) 文件是从 Windows XP 及更高版本中最近使用的文档列表中过滤出来的。尽管 SHAddToRecentDocs 将接受可执行文件的路径,但该文件不会出现在“最近的项目”列表中。

这是我的代码。我正在经历一些困难,因为我的开发环境使用的是较旧的 Windows SDK(所以我必须为自己创建 PKEY_Title),并且我的应用程序需要支持 Win2k(所以我不想绑定到像 InitPropVariantFromString 这样的函数 需要较新的 Windows 版本)。

HRESULT hr;
IShellLink* link;

// Get a pointer to the IShellLink interface.
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&link);
if (FAILED(hr))
    return;
link->SetPath(path_to_app);
link->SetArguments(L"/some /args");
link->SetDescription(L"A description");  // Turns into tooltip

IPropertyStore* prop_store;
hr = link->QueryInterface(&prop_store);
if(SUCCEEDED(hr))
{
    PROPVARIANT pv;
    pv.vt=VT_LPWSTR;
    pv.pwszVal=L"Name of item"; // Turns into actual item name

    PROPERTYKEY PKEY_Title;
    CLSIDFromString(L"{F29F85E0-4FF9-1068-AB91-08002B27B3D9}", &(PKEY_Title.fmtid));
    PKEY_Title.pid=2;

    // Set the title property.
    hr = prop_store->SetValue(PKEY_Title, pv); // THIS is where the displayed title is actually set

    // Save the changes we made to the property store
    prop_store->Commit();
    prop_store->Release();
}

SHARDAPPIDINFOLINK appinfo;
appinfo.pszAppID=L"Company.AppName"; // Previously registered using SetCurrentProcessExplicitAppUserModelID
appinfo.psl=link;
SHAddToRecentDocs(SHARD_APPIDINFOLINK, &appinfo);
link->Release();

The code in the answer to question 1671793 goes part of the way. You want an IShellLink instead of an IShellItem. I tried that code bit by bit. Things wouldn't work before using the IPropertyStore to set the title. The IPersistFile code doesn't seem to be necessary.

All of that said, while I now have items appearing when I right-click on my app's taskbar icon, I don't yet have them appearing as a sub-menu of my app on the start menu (as word docs do, for example), so I'm not yet entirely satisfied. I think this is a result of the warning in the docs for SHAddToRecentDocs:

Executable (.exe) files are filtered from the recently used documents list in Windows XP and later versions. Although SHAddToRecentDocs will accept the path of an executable file, that file will not appear in the Recent Items list.

Here's my code as it stands. I'm jumping through some hoops as my development environment is using an older Windows SDK (so I have to create PKEY_Title for myself) and my app needs to support Win2k (so I don't want to bind to functions like InitPropVariantFromString which require newer Windows versions).

HRESULT hr;
IShellLink* link;

// Get a pointer to the IShellLink interface.
hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&link);
if (FAILED(hr))
    return;
link->SetPath(path_to_app);
link->SetArguments(L"/some /args");
link->SetDescription(L"A description");  // Turns into tooltip

IPropertyStore* prop_store;
hr = link->QueryInterface(&prop_store);
if(SUCCEEDED(hr))
{
    PROPVARIANT pv;
    pv.vt=VT_LPWSTR;
    pv.pwszVal=L"Name of item"; // Turns into actual item name

    PROPERTYKEY PKEY_Title;
    CLSIDFromString(L"{F29F85E0-4FF9-1068-AB91-08002B27B3D9}", &(PKEY_Title.fmtid));
    PKEY_Title.pid=2;

    // Set the title property.
    hr = prop_store->SetValue(PKEY_Title, pv); // THIS is where the displayed title is actually set

    // Save the changes we made to the property store
    prop_store->Commit();
    prop_store->Release();
}

SHARDAPPIDINFOLINK appinfo;
appinfo.pszAppID=L"Company.AppName"; // Previously registered using SetCurrentProcessExplicitAppUserModelID
appinfo.psl=link;
SHAddToRecentDocs(SHARD_APPIDINFOLINK, &appinfo);
link->Release();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文