forked from coddec/Classic-Shell
- Notifications
You must be signed in to change notification settings - Fork 452
/
Copy pathJumpLists.cpp
661 lines (612 loc) · 19.7 KB
/
JumpLists.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
// Classic Shell (c) 2009-2017, Ivo Beltchev
// Open-Shell (c) 2017-2018, The Open-Shell Team
// Confidential information of Ivo Beltchev. Not for disclosure or distribution without prior written consent from the author
#include"stdafx.h"
#include"JumpLists.h"
#include"ItemManager.h"
#include"ResourceHelper.h"
#include"Translations.h"
#include"FNVHash.h"
#include"LogManager.h"
#include<propkey.h>
#include<StrSafe.h>
staticconst CLSID CLSID_AutomaticDestinationList={0xf0ae1542, 0xf497, 0x484b, {0xa1, 0x75, 0xa2, 0x0d, 0xb0, 0x91, 0x44, 0xba}};
structAPPDESTCATEGORY
{
int type;
union
{
wchar_t *name;
int subType;
};
int count;
int pad[10]; // just in case
};
staticconst GUID IID_IDestinationList={0x03f1eed2, 0x8676, 0x430b, {0xab, 0xe1, 0x76, 0x5c, 0x1d, 0x8f, 0xe1, 0x47}};
staticconst GUID IID_IDestinationList10a={0xfebd543d, 0x1f7b, 0x4b38, {0x94, 0x0b, 0x59, 0x33, 0xbd, 0x2c, 0xb2, 0x1b}}; // 10240
staticconst GUID IID_IDestinationList10b={0x507101cd, 0xf6ad, 0x46c8, {0x8e, 0x20, 0xee, 0xb9, 0xe6, 0xba, 0xc4, 0x7f}}; // 10547
interface IDestinationList: public IUnknown
{
public:
STDMETHOD(SetMinItems)();
virtual HRESULT STDMETHODCALLTYPE SetApplicationID( LPCWSTR appUserModelId ) = 0;
STDMETHOD(GetSlotCount)();
virtual HRESULT STDMETHODCALLTYPE GetCategoryCount( UINT *pCount ) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCategory( UINT index, int getCatFlags, APPDESTCATEGORY *pCategory ) = 0;
STDMETHOD(DeleteCategory)();
virtual HRESULT STDMETHODCALLTYPE EnumerateCategoryDestinations( UINT index, REFIID riid, void **ppvObject ) = 0;
STDMETHOD(RemoveDestination)( IUnknown *pItem );
STDMETHOD(ResolveDestination)();
};
staticconst GUID IID_IAutomaticDestinationList={0xbc10dce3, 0x62f2, 0x4bc6, {0xaf, 0x37, 0xdb, 0x46, 0xed, 0x78, 0x73, 0xc4}};
staticconst GUID IID_IAutomaticDestinationList10b={0xe9c5ef8d, 0xfd41, 0x4f72, {0xba, 0x87, 0xeb, 0x03 ,0xba, 0xd5, 0x81, 0x7c}}; // 10547
interface IAutomaticDestinationList: public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Initialize( LPCWSTR appUserModelId, LPCWSTR lnkPath, LPCWSTR ) = 0;
virtual HRESULT STDMETHODCALLTYPE HasList( BOOL *pHasList ) = 0;
virtual HRESULT STDMETHODCALLTYPE GetList( int listType, unsignedint maxCount, REFIID riid, void **ppvObject ) = 0;
STDMETHOD(AddUsagePoint)();
virtual HRESULT STDMETHODCALLTYPE PinItem( IUnknown *pItem, int pinIndex ) = 0; // -1 - pin, -2 - unpin
STDMETHOD(IsPinned)();
virtual HRESULT STDMETHODCALLTYPE RemoveDestination( IUnknown *pItem ) = 0;
STDMETHOD(SetUsageData)();
STDMETHOD(GetUsageData)();
STDMETHOD(ResolveDestination)();
virtual HRESULT STDMETHODCALLTYPE ClearList( int listType ) = 0;
};
interface IAutomaticDestinationList10b: public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Initialize( LPCWSTR appUserModelId, LPCWSTR lnkPath, LPCWSTR ) = 0;
virtual HRESULT STDMETHODCALLTYPE HasList( BOOL *pHasList ) = 0;
virtual HRESULT STDMETHODCALLTYPE GetList( int listType, unsignedint maxCount, unsignedint flags, REFIID riid, void **ppvObject ) = 0;
STDMETHOD(AddUsagePoint)();
virtual HRESULT STDMETHODCALLTYPE PinItem( IUnknown *pItem, int pinIndex ) = 0; // -1 - pin, -2 - unpin
STDMETHOD(IsPinned)();
virtual HRESULT STDMETHODCALLTYPE RemoveDestination( IUnknown *pItem ) = 0;
STDMETHOD(SetUsageData)();
STDMETHOD(GetUsageData)();
STDMETHOD(ResolveDestination)();
virtual HRESULT STDMETHODCALLTYPE ClearList( int listType ) = 0;
};
classCAutomaticList
{
public:
CAutomaticList( constwchar_t *appid );
boolHasList( void );
CComPtr<IObjectCollection> GetList( int listType, unsignedint maxCount );
voidPinItem( IUnknown *pItem, int pinIndex );
boolRemoveDestination( IUnknown *pItem );
private:
CComPtr<IAutomaticDestinationList> m_pAutoList;
CComPtr<IAutomaticDestinationList10b> m_pAutoList10b;
};
CAutomaticList::CAutomaticList( constwchar_t *appid )
{
CComPtr<IUnknown> pAutoListUnk;
if (SUCCEEDED(pAutoListUnk.CoCreateInstance(CLSID_AutomaticDestinationList)))
{
pAutoListUnk->QueryInterface(IID_IAutomaticDestinationList,(void**)&m_pAutoList);
if (m_pAutoList)
{
if (FAILED(m_pAutoList->Initialize(appid,NULL,NULL)))
m_pAutoList=NULL;
}
elseif (GetWinVersion()>=WIN_VER_WIN10)
{
pAutoListUnk->QueryInterface(IID_IAutomaticDestinationList10b,(void**)&m_pAutoList10b);
if (m_pAutoList10b)
{
if (FAILED(m_pAutoList10b->Initialize(appid,NULL,NULL)))
m_pAutoList10b=NULL;
}
}
}
}
boolCAutomaticList::HasList( void )
{
BOOL hasList;
if (m_pAutoList)
{
if (FAILED(m_pAutoList->HasList(&hasList)) || !hasList)
returnfalse;
}
elseif (m_pAutoList10b)
{
if (FAILED(m_pAutoList10b->HasList(&hasList)) || !hasList)
returnfalse;
}
else
returnfalse;
CComPtr<IObjectCollection> pCollection;
UINT count;
pCollection=GetList(1,1);
if (pCollection && SUCCEEDED(pCollection->GetCount(&count)) && count>0)
returntrue;
pCollection=GetList(0,1);
if (pCollection && SUCCEEDED(pCollection->GetCount(&count)) && count>0)
returntrue;
returnfalse;
}
CComPtr<IObjectCollection> CAutomaticList::GetList( int listType, unsignedint maxCount )
{
CComPtr<IObjectCollection> pCollection;
if (m_pAutoList)
m_pAutoList->GetList(listType,maxCount,IID_IObjectCollection,(void**)&pCollection);
elseif (m_pAutoList10b)
m_pAutoList10b->GetList(listType,maxCount,1,IID_IObjectCollection,(void**)&pCollection);
return pCollection;
}
voidCAutomaticList::PinItem( IUnknown *pItem, int pinIndex )
{
if (m_pAutoList)
m_pAutoList->PinItem(pItem,pinIndex);
elseif (m_pAutoList10b)
m_pAutoList10b->PinItem(pItem,pinIndex);
}
boolCAutomaticList::RemoveDestination( IUnknown *pItem )
{
if (m_pAutoList)
returnSUCCEEDED(m_pAutoList->RemoveDestination(pItem));
elseif (m_pAutoList10b)
returnSUCCEEDED(m_pAutoList10b->RemoveDestination(pItem));
returnfalse;
}
static CComPtr<IDestinationList> GetCustomList( constwchar_t *appid )
{
CComPtr<IUnknown> pCustomListUnk;
if (SUCCEEDED(pCustomListUnk.CoCreateInstance(CLSID_DestinationList)))
{
CComPtr<IDestinationList> pCustomList;
if (GetWinVersion()<WIN_VER_WIN10)
pCustomListUnk->QueryInterface(IID_IDestinationList,(void**)&pCustomList);
else
{
if (FAILED(pCustomListUnk->QueryInterface(IID_IDestinationList10a,(void**)&pCustomList)))
pCustomListUnk->QueryInterface(IID_IDestinationList10b,(void**)&pCustomList);
}
if (pCustomList && SUCCEEDED(pCustomList->SetApplicationID(appid)))
return pCustomList;
}
return CComPtr<IDestinationList>();
}
// Returns true if the given app has a non-empty jumplist
boolHasJumplist( constwchar_t *appid )
{
Assert(GetWinVersion()>=WIN_VER_WIN7);
CComPtr<IDestinationList> pCustomList=GetCustomList(appid);
if (pCustomList)
{
UINT count;
if (SUCCEEDED(pCustomList->GetCategoryCount(&count)) && count>0)
{
// skip Settings app (it reports one category with unsupported type, thus jump-list will be empty)
if (wcscmp(appid, L"windows.immersivecontrolpanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel") == 0)
returnfalse;
returntrue;
}
}
if (CAutomaticList(appid).HasList())
returntrue;
returnfalse;
}
staticunsignedintCalcLinkHash( IShellLink *pLink )
{
CAbsolutePidl pidl;
if (FAILED(pLink->GetIDList(&pidl)))
return0;
unsignedint hash=FNV_HASH0;
CComString pName;
if (SUCCEEDED(SHGetNameFromIDList(pidl,SIGDN_DESKTOPABSOLUTEPARSING,&pName)))
{
pName.MakeUpper();
hash=CalcFNVHash(pName);
}
CComQIPtr<IPropertyStore> pStore=pLink;
if (pStore)
hash=CalcFNVHash(GetPropertyStoreString(pStore,PKEY_Link_Arguments),hash);
return hash;
}
staticvoidAddJumpItem( CJumpGroup &group, IUnknown *pUnknown, std::vector<CComPtr<IShellItem>> &ignoreItems, std::vector<unsignedint> &ignoreLinks )
{
CJumpItem item;
item.type=CJumpItem::TYPE_UNKNOWN;
item.pItem=pUnknown;
item.hash=0;
item.bHidden=false;
item.bHasArguments=false;
CComQIPtr<IShellItem> pItem=pUnknown;
if (pItem)
{
for (std::vector<CComPtr<IShellItem>>::const_iterator it=ignoreItems.begin();it!=ignoreItems.end();++it)
{
int order;
if (SUCCEEDED(pItem->Compare(*it,SICHINT_CANONICAL|SICHINT_TEST_FILESYSPATH_IF_NOT_EQUAL,&order)) && order==0)
return;
}
item.type=CJumpItem::TYPE_ITEM;
CComString pName;
if (FAILED(pItem->GetDisplayName(SIGDN_NORMALDISPLAY,&pName)))
return;
item.name=pName;
pName.Clear();
if (SUCCEEDED(pItem->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING,&pName)))
{
LOG_MENU(LOG_OPEN,L"Jumplist Item Path: %s",(constwchar_t*)pName);
pName.MakeUpper();
item.hash=CalcFNVHash(pName);
}
LOG_MENU(LOG_OPEN,L"Jumplist Item Name: %s",item.name);
group.items.push_back(item);
return;
}
CComQIPtr<IShellLink> pLink=pUnknown;
if (pLink)
{
unsignedint hash=CalcLinkHash(pLink);
for (std::vector<unsignedint>::const_iterator it=ignoreLinks.begin();it!=ignoreLinks.end();++it)
{
if (hash==*it)
return;
}
item.type=CJumpItem::TYPE_LINK;
CComQIPtr<IPropertyStore> pStore(pLink);
if (pStore)
{
PROPVARIANT val;
PropVariantInit(&val);
if (group.type==CJumpGroup::TYPE_TASKS && SUCCEEDED(pStore->GetValue(PKEY_AppUserModel_IsDestListSeparator,&val)) && val.vt==VT_BOOL && val.boolVal)
{
item.type=CJumpItem::TYPE_SEPARATOR;
PropVariantClear(&val);
}
else
{
CString str=GetPropertyStoreString(pStore,PKEY_Title);
if (!str.IsEmpty())
{
wchar_t name[256];
SHLoadIndirectString(str,name,_countof(name),NULL);
item.name=name;
}
}
}
CAbsolutePidl pidl;
if (SUCCEEDED(pLink->GetIDList(&pidl)))
{
CComString pName;
if (item.name.IsEmpty())
{
if (SUCCEEDED(SHGetNameFromIDList(pidl,SIGDN_NORMALDISPLAY,&pName)))
{
item.name=pName;
}
}
pName.Clear();
if (SUCCEEDED(SHGetNameFromIDList(pidl,SIGDN_DESKTOPABSOLUTEPARSING,&pName)))
{
LOG_MENU(LOG_OPEN,L"Jumplist Link Path: %s",(constwchar_t*)pName);
pName.MakeUpper();
item.hash=CalcFNVHash(pName);
}
CComQIPtr<IPropertyStore> pStore(pLink);
if (pStore)
{
CString args=GetPropertyStoreString(pStore,PKEY_Link_Arguments);
if (!args.IsEmpty())
{
LOG_MENU(LOG_OPEN,L"Jumplist Link Args: %s",args);
item.hash=CalcFNVHash(args,item.hash);
item.bHasArguments=true;
}
}
}
LOG_MENU(LOG_OPEN,L"Jumplist Link Name: %s",item.name);
#ifdef _DEBUG
LogPropertyStore(LOG_OPEN, pStore);
#endif
if (!item.name.IsEmpty())
group.items.push_back(item);
return;
}
}
staticvoidAddJumpCollection( CJumpGroup &group, IObjectCollection *pCollection, std::vector<CComPtr<IShellItem>> &ignoreItems, std::vector<unsignedint> &ignoreLinks )
{
UINT count;
if (SUCCEEDED(pCollection->GetCount(&count)))
{
for (UINT i=0;i<count;i++)
{
CComPtr<IUnknown> pUnknown;
if (SUCCEEDED(pCollection->GetAt(i,IID_IUnknown,(void**)&pUnknown)) && pUnknown)
AddJumpItem(group,pUnknown,ignoreItems,ignoreLinks);
}
}
}
// Returns the jumplist for the given shortcut
boolGetJumplist( constwchar_t *appid, CJumpList &list, int maxCount, int maxHeight, int sepHeight, int itemHeight )
{
Assert(GetWinVersion()>=WIN_VER_WIN7);
list.Clear();
UINT categoryCount=0;
CComPtr<IDestinationList> pCustomList=GetCustomList(appid);
if (pCustomList)
{
if (FAILED(pCustomList->GetCategoryCount(&categoryCount)))
categoryCount=0;
}
list.groups.reserve(categoryCount+2);
std::vector<CComPtr<IShellItem>> ignoreItems;
std::vector<unsignedint> ignoreLinks;
CAutomaticList autoList(appid);
{
// add pinned
CComPtr<IObjectCollection> pPinnedList=autoList.GetList(0,maxCount);
if (pPinnedList)
{
Assert(list.groups.empty());
list.groups.resize(list.groups.size()+1);
CJumpGroup &group=*list.groups.rbegin();
group.type=CJumpGroup::TYPE_PINNED;
group.name=FindTranslation(L"JumpList.Pinned",L"Pinned");
AddJumpCollection(group,pPinnedList,ignoreItems,ignoreLinks);
for (std::vector<CJumpItem>::const_iterator it=group.items.begin();it!=group.items.end();++it)
{
CComQIPtr<IShellItem> pShellItem(it->pItem);
if (pShellItem)
ignoreItems.push_back(pShellItem);
else
{
CComQIPtr<IShellLink> pLink(it->pItem);
if (pLink)
{
unsignedint hash=CalcLinkHash(pLink);
if (hash)
ignoreLinks.push_back(hash);
}
}
}
}
}
int taskIndex=-1;
for (UINT catIndex=0;catIndex<categoryCount;catIndex++)
{
APPDESTCATEGORY category={0};
if (SUCCEEDED(pCustomList->GetCategory(catIndex,1,&category)))
{
if (category.type==0)
{
// custom group
if (category.name)
{
wchar_t name[256];
SHLoadIndirectString(category.name,name,_countof(name),NULL);
CoTaskMemFree(category.name);
CComPtr<IObjectCollection> pCollection;
if (SUCCEEDED(pCustomList->EnumerateCategoryDestinations(catIndex,IID_IObjectCollection,(void**)&pCollection)))
{
list.groups.resize(list.groups.size()+1);
CJumpGroup &group=*list.groups.rbegin();
group.name=name;
group.type=CJumpGroup::TYPE_CUSTOM;
AddJumpCollection(group,pCollection,ignoreItems,ignoreLinks);
}
}
}
elseif (category.type==1)
{
// standard group
if (category.subType==1 || category.subType==2)
{
CComPtr<IObjectCollection> pCollection=autoList.GetList(3-category.subType,maxCount);
if (pCollection)
{
list.groups.resize(list.groups.size()+1);
CJumpGroup &group=*list.groups.rbegin();
if (category.subType==1)
{
group.type=CJumpGroup::TYPE_FREQUENT;
group.name=FindTranslation(L"JumpList.Frequent",L"Frequent");
}
else
{
group.type=CJumpGroup::TYPE_RECENT;
group.name=FindTranslation(L"JumpList.Recent",L"Recent");
}
AddJumpCollection(group,pCollection,ignoreItems,ignoreLinks);
}
}
}
elseif (category.type==2 && taskIndex==-1)
{
taskIndex=catIndex;
}
}
}
if (taskIndex!=-1)
{
// add tasks
CComPtr<IObjectCollection> pCollection;
if (SUCCEEDED(pCustomList->EnumerateCategoryDestinations(taskIndex,IID_IObjectCollection,(void**)&pCollection)))
{
list.groups.resize(list.groups.size()+1);
CJumpGroup &group=*list.groups.rbegin();
group.name=FindTranslation(L"JumpList.Tasks",L"Tasks");
group.type=CJumpGroup::TYPE_TASKS;
AddJumpCollection(group,pCollection,ignoreItems,ignoreLinks);
}
}
if (categoryCount==0)
{
// add recent
CComPtr<IObjectCollection> pRecentList=autoList.GetList(1,maxCount);
if (pRecentList)
{
list.groups.resize(list.groups.size()+1);
CJumpGroup &group=*list.groups.rbegin();
group.type=CJumpGroup::TYPE_RECENT;
group.name=FindTranslation(L"JumpList.Recent",L"Recent");
AddJumpCollection(group,pRecentList,ignoreItems,ignoreLinks);
}
}
// limit the item count (not tasks or pinned)
for (std::vector<CJumpGroup>::iterator it=list.groups.begin();it!=list.groups.end();++it)
{
CJumpGroup &group=*it;
if (group.type==CJumpGroup::TYPE_TASKS || group.type==CJumpGroup::TYPE_PINNED)
maxHeight-=sepHeight+(int)group.items.size()*itemHeight;
}
for (std::vector<CJumpGroup>::iterator it=list.groups.begin();it!=list.groups.end();++it)
{
CJumpGroup &group=*it;
if (group.type!=CJumpGroup::TYPE_TASKS && group.type!=CJumpGroup::TYPE_PINNED)
{
maxHeight-=sepHeight;
for (std::vector<CJumpItem>::iterator it2=group.items.begin();it2!=group.items.end();++it2)
if (!it2->bHidden)
{
it2->bHidden=(maxCount<=0 || maxHeight<itemHeight);
maxCount--;
maxHeight-=itemHeight;
}
}
}
// hide empty groups
for (std::vector<CJumpGroup>::iterator it=list.groups.begin();it!=list.groups.end();++it)
{
CJumpGroup &group=*it;
group.bHidden=true;
for (std::vector<CJumpItem>::const_iterator it2=group.items.begin();it2!=group.items.end();++it2)
if (!it2->bHidden)
{
group.bHidden=false;
break;
}
}
returntrue;
}
// Executes the given item using the correct application
boolExecuteJumpItem( const CItemManager::ItemInfo *pAppInfo, const CJumpItem &item, HWND hwnd )
{
Assert(GetWinVersion()>=WIN_VER_WIN7);
if (!item.pItem)
returnfalse;
if (item.type==CJumpItem::TYPE_ITEM)
{
CComQIPtr<IShellItem> pItem(item.pItem);
if (!pItem)
returnfalse;
SHELLEXECUTEINFO execute={sizeof(execute),SEE_MASK_IDLIST|SEE_MASK_FLAG_LOG_USAGE};
execute.nShow=SW_SHOWNORMAL;
CAbsolutePidl pidl;
if (SUCCEEDED(SHGetIDListFromObject(pItem,&pidl)))
{
execute.lpIDList=pidl;
ShellExecuteEx(&execute);
}
returntrue;
}
if (item.type==CJumpItem::TYPE_LINK)
{
// Name: System.AppUserModel.HostEnvironment -- PKEY_AppUserModel_HostEnvironment
// Type: UInt32 -- VT_UI4
// FormatID: {9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}, 14
staticconst PROPERTYKEY PKEY_AppUserModel_HostEnvironment = { {0x9F4C2855, 0x9F79, 0x4B39, {0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3}}, 14 };
// Name: System.AppUserModel.ActivationContext -- PKEY_AppUserModel_ActivationContext
// Type: String -- VT_LPWSTR
// FormatID: {9F4C2855-9F79-4B39-A8D0-E1D42DE1D5F3}, 20
staticconst PROPERTYKEY PKEY_AppUserModel_ActivationContext = { {0x9F4C2855, 0x9F79, 0x4B39, {0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3}}, 20 };
CComQIPtr<IContextMenu> pMenu(item.pItem);
CStringA params;
CComQIPtr<IShellLink> pLink(item.pItem);
if (pLink)
{
CComQIPtr<IPropertyStore> store(pLink);
if (store)
{
auto appId = GetPropertyStoreString(store, PKEY_AppUserModel_ID);
if (!appId.IsEmpty())
{
CComPtr<IShellItem2> target;
if (SUCCEEDED(SHCreateItemInKnownFolder(FOLDERID_AppsFolder, 0, appId, IID_PPV_ARGS(&target))))
{
ULONG modern = 0;
if (SUCCEEDED(target->GetUInt32(PKEY_AppUserModel_HostEnvironment, &modern)) && modern)
{
CComQIPtr<IContextMenu> targetMenu;
if (SUCCEEDED(target->BindToHandler(nullptr, BHID_SFUIObject, IID_PPV_ARGS(&targetMenu))))
{
pMenu = targetMenu;
params = CT2CA(GetPropertyStoreString(store, PKEY_AppUserModel_ActivationContext));
}
}
}
}
}
}
// invoke the link through its context menu
if (!pMenu)
returnfalse;
HRESULT hr;
HMENU menu=CreatePopupMenu();
hr=pMenu->QueryContextMenu(menu,0,1,1000,CMF_DEFAULTONLY);
if (FAILED(hr))
{
DestroyMenu(menu);
returnfalse;
}
int id=GetMenuDefaultItem(menu,FALSE,0);
if (id>0)
{
CMINVOKECOMMANDINFO command={sizeof(command),CMIC_MASK_FLAG_LOG_USAGE};
command.lpVerb=MAKEINTRESOURCEA(id-1);
if (!params.IsEmpty())
command.lpParameters = params;
wchar_t path[_MAX_PATH];
GetModuleFileName(NULL,path,_countof(path));
if (_wcsicmp(PathFindFileName(path),L"explorer.exe")==0)
command.fMask|=CMIC_MASK_ASYNCOK;
command.hwnd=hwnd;
command.nShow=SW_SHOWNORMAL;
hr=pMenu->InvokeCommand(&command);
}
DestroyMenu(menu);
}
returntrue;
}
// Removes the given item from the jumplist
voidRemoveJumpItem( const CItemManager::ItemInfo *pAppInfo, CJumpList &list, int groupIdx, int itemIdx )
{
CString appid;
{
CItemManager::RWLock lock(&g_ItemManager,false,CItemManager::RWLOCK_ITEMS);
appid=pAppInfo->GetAppid();
}
CJumpGroup &group=list.groups[groupIdx];
if (group.type==CJumpGroup::TYPE_FREQUENT || group.type==CJumpGroup::TYPE_RECENT)
{
if (CAutomaticList(appid).RemoveDestination(group.items[itemIdx].pItem))
group.items.erase(group.items.begin()+itemIdx);
}
else
{
CComPtr<IDestinationList> pCustomList=GetCustomList(appid);
if (pCustomList)
{
if (SUCCEEDED(pCustomList->RemoveDestination(group.items[itemIdx].pItem)))
group.items.erase(group.items.begin()+itemIdx);
}
}
}
// Pins or unpins the given item from the jumplist
voidPinJumpItem( const CItemManager::ItemInfo *pAppInfo, const CJumpList &list, int groupIdx, int itemIdx, bool bPin, int pinIndex )
{
CString appid;
{
CItemManager::RWLock lock(&g_ItemManager,false,CItemManager::RWLOCK_ITEMS);
appid=pAppInfo->GetAppid();
}
const CJumpGroup &group=list.groups[groupIdx];
CAutomaticList(appid).PinItem(group.items[itemIdx].pItem,bPin?pinIndex:-2);
}