4 * @brief Implementation file for JumpList helper functions.
11 #include <propvarutil.h>
20 TCHAR g_exe_path[260];
22 IShellLink *CreateShellLink(const String& app_path, const String& params, const String& title, const String& desc, int icon_index)
25 IShellLink *pShellLink = NULL;
26 if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
27 IID_IShellLink, (void **)&pShellLink)))
30 String app_path2(app_path);
33 if (g_exe_path[0] == '\0')
34 GetModuleFileName(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)))
45 std::wstring title2 = ucr::toUTF16((title.empty()) ? params : title);
47 InitPropVariantFromString(title2.c_str(), &pv);
48 pPS->SetValue(PKEY_Title, pv);
49 PropVariantClear(&pv);
65 bool SetCurrentProcessExplicitAppUserModelID(const std::wstring& appid)
68 HMODULE hLibrary = GetModuleHandle(_T("shell32.dll"));
71 HRESULT (__stdcall *pfnSetCurrentProcessExplicitAppUserModelID)(PCWSTR AppID) =
72 (HRESULT (__stdcall *)(PCWSTR))GetProcAddress(hLibrary, "SetCurrentProcessExplicitAppUserModelID");
73 if (!pfnSetCurrentProcessExplicitAppUserModelID)
75 return pfnSetCurrentProcessExplicitAppUserModelID(appid.c_str()) == S_OK;
78 bool AddToRecentDocs(const String& app_path, const String& params, const String& title, const String& desc, int icon_index)
81 SHARDAPPIDINFOLINK saiil;
82 saiil.pszAppID = g_appid.c_str();
83 saiil.psl = CreateShellLink(app_path, params, title, desc, icon_index);
86 SHAddToRecentDocs(SHARD_APPIDINFOLINK, &saiil);