对于Windows 7跳转列表中最新的资料自定义标题(Custom titles for Windo

2019-10-18 03:44发布

匆匆问:我有一些新的任务栏的API在Windows 7和玩弄已经得到了我的应用程序跳转列表,最近的项目展现出来,但我想在不同的标题不是文件名,以显示他们(大部分文件我的应用程序将开幕将有非常相似的名称)。 我看不出有什么办法做到这一点与的IShellItem接口,虽然。 我将不得不使用自定义类别和IShellLinks做到这一点?

作为参考,我当前的代码如下所示:

void AddRecentApp(const wchar_t* path, const wchar_t* title /* Can I even use this? */ ) {
    HRESULT hres;

    hres = CoInitialize(NULL);

    IShellItem* recentItem;
    hres = SHCreateItemFromParsingName(path, NULL, IID_PPV_ARGS(&recentItem));
    if(SUCCEEDED(hres)) {
        SHARDAPPIDINFO recentItemInfo;
        recentItemInfo.pszAppID = MY_APP_USER_MODEL_ID;
        recentItemInfo.psi = recentItem;

        SHAddToRecentDocs(SHARD_APPIDINFO, &recentItemInfo);

        recentItem->Release();
    }
}

Answer 1:

弄清楚了。 IShellItems是一个文件只是一种表象,所以他们只将提供该文件的信息(没有自定义标题等)的的IShellLink本质上是一个快捷方式,更加灵活的时候推出所显示的术语和操作,所以更适合在这种情况下。 这是我的新的代码:

void AddRecentApp(const wchar_t* path, const wchar_t* title) {
    HRESULT hres;
    hres = CoInitialize(NULL);

    // Shell links give us more control over how the item is displayed and run
    IShellLink* shell_link;
    hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shell_link));
    if(SUCCEEDED(hres)) {
        // Set up the basic link properties
        shell_link->SetPath(path);
        shell_link->SetArguments(L"--some-command-line-here"); // command line to execute when item is opened here!
        shell_link->SetDescription(title); // This is what shows in the tooltip
        shell_link->SetIconLocation(L"/path/to/desired/icon", 0); // can be an icon file or binary

        // Open up the links property store and change the title
        IPropertyStore* prop_store;
        hres = shell_link->QueryInterface(IID_PPV_ARGS(&prop_store));
        if(SUCCEEDED(hres)) {
            PROPVARIANT pv;
            InitPropVariantFromString(title, &pv);

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

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

        // The link must persist in the file system somewhere, save it here.
        IPersistFile* persist_file; 
        hres = shell_link->QueryInterface(IID_PPV_ARGS(&persist_file));
        if(SUCCEEDED(hres)) {
            hres = persist_file->Save(L"/link/save/directory", TRUE); 
            persist_file->Release(); 
        }

        // Add the link to the recent documents list
        SHARDAPPIDINFOLINK app_id_info_link;
        app_id_info_link.pszAppID = MY_APP_USER_MODEL_ID;
        app_id_info_link.psl = shell_link;
        SHAddToRecentDocs(SHARD_APPIDINFOLINK, &app_id_info_link);

        shell_link->Release();
    }
}  


文章来源: Custom titles for Windows 7 Jump List Recent items