4 * @brief Implementation file for JumpList helper functions.
11 #include <propvarutil.h>
20 wchar_t g_exe_path[260];
22 IShellLinkW *CreateShellLink(const std::wstring& app_path, const std::wstring& params, const std::wstring& title, const std::wstring& desc, int icon_index)
25 IShellLinkW *pShellLink = NULL;
26 if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
27 IID_IShellLinkW, (void **)&pShellLink)))
30 std::wstring app_path2(app_path);
33 if (g_exe_path[0] == '\0')
34 GetModuleFileNameW(NULL, g_exe_path, sizeof(g_exe_path));
35 app_path2 = g_exe_path;
37 pShellLink->SetPath(app_path2.c_str());
38 pShellLink->SetIconLocation(app_path2.c_str(), icon_index);
39 pShellLink->SetArguments(params.c_str());
40 pShellLink->SetDescription(desc.c_str());
42 IPropertyStore *pPS = NULL;
43 if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
46 InitPropVariantFromString(title.c_str(), &pv);
47 pPS->SetValue(PKEY_Title, pv);
48 PropVariantClear(&pv);
64 bool SetCurrentProcessExplicitAppUserModelID(const std::wstring& appid)
67 HMODULE hLibrary = GetModuleHandle(_T("shell32.dll"));
70 HRESULT (__stdcall *pfnSetCurrentProcessExplicitAppUserModelID)(PCWSTR AppID) =
71 (HRESULT (__stdcall *)(PCWSTR))GetProcAddress(hLibrary, "SetCurrentProcessExplicitAppUserModelID");
72 if (!pfnSetCurrentProcessExplicitAppUserModelID)
74 return pfnSetCurrentProcessExplicitAppUserModelID(appid.c_str()) == S_OK;
77 bool AddToRecentDocs(const String& app_path, const String& params, const String& title, const String& desc, int icon_index)
80 SHARDAPPIDINFOLINK saiil;
81 saiil.pszAppID = g_appid.c_str();
83 saiil.psl = CreateShellLink(app_path, params, title, desc, icon_index);
85 saiil.psl = (IShellLink *)CreateShellLink(ucr::toUTF16(app_path), ucr::toUTF16(params), ucr::toUTF16(title), ucr::toUTF16(desc), icon_index);
89 SHAddToRecentDocs(SHARD_APPIDINFOLINK, &saiil);