WEB开发网
开发学院操作系统Windows 7 Windows 7 新特性 Shell Library 编程接口介绍 阅读

Windows 7 新特性 Shell Library 编程接口介绍

 2009-09-04 00:00:00 来源:WEB开发网   
核心提示: C# AddFolderToShellLibraryusing (ShellLibrary library = ShellLibrary.Load(libraryName, false)){ /**// // Add a folder to the shell library. // // A

C# AddFolderToShellLibrary

using (ShellLibrary library = ShellLibrary.Load(libraryName, false))
{
    /**//////////////////////////////////////////////////////////////////
    // Add a folder to the shell library.
    //

    // Add the folder to the shell library
    library.Add(folderPath);
    library.DefaultSaveFolder = folderPath;
}

枚举Shell Library中的文件夹

IShellLibrary::GetFolders可用来得到Shell Library中的文件夹。

C++ ListFoldersInShellLibrary

/**//*!
* List all folders in the shell library.
*
* \param pShellLib
* The IShellLibrary interface of the shell library
*/
void ListFoldersInShellLibrary(IShellLibrary* pShellLib)
{
    HRESULT hr = S_OK;

    IShellItemArray* pShellItemArray = NULL;
    pShellLib->GetFolders(LFF_ALLITEMS, IID_PPV_ARGS(&pShellItemArray));
    if (FAILED(hr))
    {
        _tprintf(_T("IShellLibrary::GetFolders failed to get the folders ") \
            _T("of the shell library w/err 0x%08lx\n"), hr);
        return;
    }

    DWORD dwFolderCount;
    pShellItemArray->GetCount(&dwFolderCount);

    // Iterate through all folders of the shell library
    for (DWORD i = 0; i < dwFolderCount; i++)
    {
        IShellItem *pShellItem;
        hr = pShellItemArray->GetItemAt(i, &pShellItem);
        if (FAILED(hr))
            continue;

        // Convert IShellItem to IShellItem2
        IShellItem2 *pShellItem2;
        pShellItem->QueryInterface(IID_PPV_ARGS(&pShellItem2));
        pShellItem->Release();

        // Fix folder path changes
        IShellItem2 *pShellItemResolvedFolder = NULL;
        hr = pShellLib->ResolveFolder(pShellItem2, 5000, IID_PPV_ARGS(
            &pShellItemResolvedFolder));
        if (SUCCEEDED(hr))
        {
            // Point to the fixed folder
            pShellItem2->Release();
            pShellItem2 = pShellItemResolvedFolder;
        }
        // Else we will show the unfixed folder

        // Print the folder path
        LPWSTR wszFolderPath;
        hr = pShellItem2->GetString(PKEY_ParsingPath, &wszFolderPath);
        if (SUCCEEDED(hr))
        {
            _putws(wszFolderPath);
        }
        CoTaskMemFree(wszFolderPath);

        // Clean up
        pShellItem2->Release();
    }

    pShellItemArray->Release();
}

上一页  1 2 3 4 5  下一页

Tags:Windows 特性 Shell

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接