Windows 10的跳转列表失败

Jumplist in Windows 10 failing

本文关键字:列表 失败 Windows      更新时间:2023-10-16

我使用下面的代码让任务栏跳转列表在某些页面打开用户的默认浏览器。

在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库有关。