Windows 10的跳转列表失败
Jumplist in Windows 10 failing
我使用下面的代码让任务栏跳转列表在某些页面打开用户的默认浏览器。
在win7/8上,一切都正常运行了大约一年,但在win10上,当单击任务栏任务时,浏览器不会被调用,微软文档显示从win8到win10没有任何变化。
bool SetUpJumpList( )
{
HRESULT hr;
CComPtr<ICustomDestinationList> pDestList;
hr = pDestList.CoCreateInstance ( CLSID_DestinationList , NULL , CLSCTX_INPROC_SERVER );
if ( FAILED ( hr ) )
{
return false;
}
hr = pDestList->SetAppID ( _TBID );
if ( FAILED ( hr ) )
{
return false;
}
UINT cMaxSlots;
CComPtr<IObjectArray> pRemovedItems;
hr = pDestList->BeginList ( &cMaxSlots , IID_PPV_ARGS ( &pRemovedItems ) );
if ( FAILED ( hr ) )
{
return false;
}
CComPtr<IObjectCollection> pObjColl;
hr = pObjColl.CoCreateInstance ( CLSID_EnumerableObjectCollection , NULL , CLSCTX_INPROC_SERVER );
if ( FAILED ( hr ) )
{
return false;
}
if ( !AddJumpListTasks ( pObjColl ) )
{
return false;
}
CComQIPtr<IObjectArray> pTasksArray = pObjColl;
if ( !pTasksArray )
{
return false;
}
hr = pDestList->AddUserTasks ( pTasksArray );
if ( FAILED ( hr ) )
{
return false;
}
hr = pDestList->CommitList( );
return SUCCEEDED ( hr );
}
bool AddJumpListTasks ( IObjectCollection* pObjColl )
{
wchar_t pBuf[ MAX_PATH ];
int bytes = GetModuleFileName ( NULL , pBuf , MAX_PATH );
CJumpListTask aTasks[ ] =
{
{ _T ( "https://www.google.co.uk" ) , _T ( "Home Page" ) , _T ( "Home" ) , 0 },
{ _T ( "https://www.google.co.uk" ) , _T ( "Twitter Page" ) , _T ( "Twitter" ) , 9 },
{ _T ( "https://www.google.co.uk" ) , _T ( "Facebook Page" ) , _T ( "Facebook" ) , 10 }
};
CString strBrowser;
DWORD size = 1024;
AssocQueryString ( 0 , ASSOCSTR_EXECUTABLE , L"http" , L"Open" , strBrowser.GetBufferSetLength ( size ) , &size );
for ( int i = 0; i < _countof ( aTasks ); i++ )
{
if ( !AddJumpListTask ( pObjColl , aTasks[ i ] , strBrowser , pBuf ) )
{
strBrowser.ReleaseBuffer( );
return false;
}
}
strBrowser.ReleaseBuffer( );
return true;
}
bool AddJumpListTask ( IObjectCollection* pObjColl , const CJumpListTask& rTask , LPCTSTR szExePath , LPCTSTR pBuf )
{
HRESULT hr;
CComPtr<IShellLink> pLink;
hr = pLink.CoCreateInstance ( CLSID_ShellLink , NULL , CLSCTX_INPROC_SERVER );
if ( FAILED ( hr ) )
{
return false;
}
hr = pLink->SetPath ( szExePath );
if ( FAILED ( hr ) )
{
return false;
}
hr = pLink->SetArguments ( rTask.szArgs );
if ( FAILED ( hr ) )
{
return false;
}
hr = pLink->SetIconLocation ( pBuf , rTask.nIconIndex );
if ( FAILED ( hr ) )
{
return false;
}
CComQIPtr<IPropertyStore> pPropStore = pLink;
PROPVARIANT pv;
if ( !pPropStore )
{
return false;
}
hr = InitPropVariantFromString ( CT2CW ( rTask.szTitle ) , &pv );
if ( FAILED ( hr ) )
{
return false;
}
hr = pPropStore->SetValue ( PKEY_Title , pv );
PropVariantClear ( &pv );
if ( FAILED ( hr ) )
{
return false;
}
hr = pPropStore->Commit( );
if ( FAILED ( hr ) )
{
return false;
}
hr = pObjColl->AddObject ( pLink );
return SUCCEEDED ( hr );
}
我注意到其他几个应用程序,如CCleaner,也使用这种方法不起作用,但微软的应用程序,如Office 2013仍然工作,所以问题是我如何让它在Windows 10上再次运行?
我确定这与 CustomDestinations -ms文件存储在CustomDestinations文件夹中没有关系,因为与Windows 10的干净安装相同的非功能出现。
使用所需的文本和图标创建任务栏任务菜单,调试显示添加了正确的URL以及正确的默认浏览器和浏览器路径。
编辑:使用Visual Studio 2015与工具集Windows XP v140_xp
如果可能的话,您可以使用最新Windows SDK中的MFC类"CJumplist"作为解决方案。
我们发现它可以解决这个问题,但只有使用最新的SDK版本。使用使用相同MFC类的旧SDK(例如Windows 7 SDK)会导致您遇到的完全相同的问题。
这是一个在Windows 10上使用VC2013和最新SDK(目标v12.0)工作的示例代码,但仅当在共享Dll中使用MFC时。与静态MFC Dll的链接似乎不起作用。
CJumpList *pJumpList = new CJumpList();
pJumpList->SetAppID(m_pszAppID);
result = pJumpList->AddTask(szPath, _T("-data1"), _T("number 4"), szPath, 0);
result = pJumpList->AddTask(szPath, _T("-data2"), _T("number 5"), szPath, 0);
pJumpList->CommitList();
delete pJumpList;
我不知道微软开发人员在这个类中做了什么改变来使它工作。我们的纯Win32代码遇到了与您报告的相同的问题。
对此进行一点更新,由于其他问题重新安装Windows,然后重新安装VS,但不检查XP兼容性选项导致Jumplists再次工作,我不需要XP支持,但我认为这个问题与XP库有关。
- 使用显式模板参数列表和 [temp.arg.explicit]/3 的函数调用的演绎失败
- 使用大括号初始值设定项列表时,模板参数推断失败
- 从 std::vector<double> 到 Python 列表的转换失败(提升 python)
- C++ 链表合并排序的实现在连接 1 个以上节点的子列表时失败
- 嵌套列表(字符串向量的向量)初始化失败
- 使用初始值设定项列表初始化结构,对于 std::array 失败
- 简单的链接列表删除失败
- std::list::merge() 对于包含对象的列表失败
- 断言失败,列表迭代器不可取消引用
- 使用链接列表实现堆栈,调试断言失败
- 为什么我的列表中的迭代失败
- 类大括号括起来的初始值设定项列表失败
- 在stl列表中调用构造函数失败
- 从初始化器列表初始化unique_ptrs的容器失败,GCC为4.7
- Visual Studio 2012 c++构建失败,但错误列表或输出中没有任何内容
- 调试断言失败!表达式列表迭代器不兼容
- 堆栈列表调试断言失败c++
- 模板初始化列表-查找失败的原因
- Windows 10的跳转列表失败
- C++11初始值设定项列表失败,但仅适用于长度为2的列表