如何以编程方式将应用程序图标固定在windows 8的地铁启动屏幕上



如何以编程方式(c++)将应用程序图标引脚到win8中的metro启动屏幕?我知道怎么手动操作。我还知道,一旦我启动该应用程序,它将自动添加。

我在这里找到了这个解决方案

BOOL PinToStart( LPCWSTR szFilePath )
{
BOOL bSuccess = FALSE;
// break into file name and path
WCHAR lpszDirectoryName[ MAX_PATH ] = { 0 };
LPCWSTR lpszFileName = ::PathFindFileName( szFilePath );
wcscpy_s( lpszDirectoryName, szFilePath );
::PathRemoveFileSpec( lpszDirectoryName );
// load shell32.dll
HMODULE hShell32 = LoadLibrary( L"SHELL32" );
if( hShell32 != NULL )
{
    // get the localized translation of 'Pin to Start' verb
    WCHAR szPinToStartLocalized[ MAX_PATH ] = { 0 };
    int nPinToStartLocalizedLength = LoadString( (HINSTANCE)hShell32, 51201, szPinToStartLocalized, MAX_PATH );
    if(  nPinToStartLocalizedLength > 0 )
    {
        // create the shell object
        IShellDispatch *pShellDispatch = NULL;
        HRESULT hr = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void**)&pShellDispatch);
        if( SUCCEEDED( hr ) )
        {
            Folder *pFolder = NULL;
            variant_t vaDirectory( lpszDirectoryName );
            // get the namespace
            if( SUCCEEDED( pShellDispatch->NameSpace( vaDirectory, &pFolder ) ) )
            {
                FolderItem *pItem = NULL;
                bstr_t vaFileName( lpszFileName );
                // parse the name
                if( SUCCEEDED( pFolder->ParseName( vaFileName, &pItem ) ) )
                {
                    FolderItemVerbs* pVerbs = NULL;
                    // get the verbs
                    if( SUCCEEDED( pItem->Verbs(&pVerbs) ) )
                    {
                        long nCount = 0;
                        if( SUCCEEDED ( pVerbs->get_Count( &nCount ) ) )
                        {
                            variant_t vaIndex;
                            vaIndex.vt = VT_I4;
                            // iterate through verbs
                            for( vaIndex.lVal = 0; vaIndex.lVal<nCount; vaIndex.lVal++ )
                            {
                                FolderItemVerb* pVerb = NULL;
                                if( SUCCEEDED( pVerbs->Item( vaIndex, &pVerb ) ) )
                                {
                                    BSTR bstrVerbName = NULL;
                                    // check for 'Pin to Start' verb
                                    if( SUCCEEDED( pVerb->get_Name( &bstrVerbName ) ) )
                                    {
                                        if( 0 == wcscmp( bstrVerbName, szPinToStartLocalized ) )
                                        {
                                            bSuccess = SUCCEEDED( pVerb->DoIt() );
                                            vaIndex.lVal = nCount; // break for
                                        }
                                        ::SysFreeString( bstrVerbName );
                                    }
                                    pVerb->Release();
                                } // if
                            } // for
                        }
                        pVerbs->Release();
                    }
                    pItem->Release();
                }
                pFolder->Release();
            }
            pShellDispatch->Release();
        }
    }
    ::FreeLibrary( hShell32 );
}
return bSuccess;
}

希望对你有帮助

相关内容

  • 没有找到相关文章

最新更新