4 * @brief Implementation file for JumpList helper functions.
12 #include <propvarutil.h>
21 wchar_t g_exe_path[260];
23 IShellLinkW *CreateShellLink(const std::wstring& app_path, const std::wstring& params, const std::wstring& title, const std::wstring& desc, int icon_index)
26 IShellLinkW *pShellLink = NULL;
27 if (FAILED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
28 IID_IShellLinkW, (void **)&pShellLink)))
31 std::wstring app_path2(app_path);
34 if (g_exe_path[0] == '\0')
35 GetModuleFileNameW(NULL, g_exe_path, sizeof(g_exe_path)/sizeof(g_exe_path[0]));
36 app_path2 = g_exe_path;
38 pShellLink->SetPath(app_path2.c_str());
39 pShellLink->SetIconLocation(app_path2.c_str(), icon_index);
40 pShellLink->SetArguments(params.c_str());
41 pShellLink->SetDescription(desc.c_str());
43 IPropertyStore *pPS = NULL;
44 if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
47 InitPropVariantFromString(title.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();
84 saiil.psl = CreateShellLink(app_path, params, title, desc, icon_index);
86 saiil.psl = (IShellLink *)CreateShellLink(ucr::toUTF16(app_path), ucr::toUTF16(params), ucr::toUTF16(title), ucr::toUTF16(desc), icon_index);
90 SHAddToRecentDocs(SHARD_APPIDINFOLINK, &saiil);
98 std::vector<Item> GetRecentDocs(size_t nMaxItems)
100 std::vector<Item> list;
102 IApplicationDocumentLists *pDocumentLists = NULL;
103 if (FAILED(CoCreateInstance(CLSID_ApplicationDocumentLists, NULL, CLSCTX_INPROC_SERVER,
104 IID_IApplicationDocumentLists, (void **)&pDocumentLists)))
106 pDocumentLists->SetAppID(g_appid.c_str());
108 IObjectArray *pObjectArray;
109 if (SUCCEEDED(pDocumentLists->GetList(ADLT_RECENT, static_cast<UINT>(nMaxItems), IID_IObjectArray, (void **)&pObjectArray)))
112 pObjectArray->GetCount(&nObjects);
113 for (UINT i = 0; i < nObjects; ++i)
115 IShellLinkW *pShellLink;
116 if (SUCCEEDED(pObjectArray->GetAt(i, IID_IShellLinkW, (void **)&pShellLink)))
118 wchar_t szPath[MAX_PATH];
119 wchar_t szDescription[MAX_PATH];
120 wchar_t szArguments[MAX_PATH * 6];
121 pShellLink->GetPath(szPath, sizeof(szPath)/sizeof(szPath[0]), NULL, SLGP_RAWPATH);
122 pShellLink->GetDescription(szDescription, sizeof(szDescription)/sizeof(szDescription[0]));
123 pShellLink->GetArguments(szArguments, sizeof(szArguments)/sizeof(szArguments[0]));
124 IPropertyStore *pPS = NULL;
126 InitPropVariantFromString(L"", &pv);
127 if (SUCCEEDED(pShellLink->QueryInterface(IID_IPropertyStore, (void **)&pPS)))
129 pPS->GetValue(PKEY_Title, &pv);
132 list.push_back(Item(ucr::toTString(szPath), ucr::toTString(szArguments), ucr::toTString(pv.bstrVal), ucr::toTString(szDescription)));
133 PropVariantClear(&pv);
134 pShellLink->Release();
137 pObjectArray->Release();
139 pDocumentLists->Release();