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

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

 2009-09-04 00:00:00 来源:WEB开发网   
核心提示: C# ShowManageLibraryUI// ShowManageLibraryUI requires that the library is not currently // opened with write permission. ShellLibrary.ShowManageLibr

C# ShowManageLibraryUI

// ShowManageLibraryUI requires that the library is not currently
// opened with write permission.
ShellLibrary.ShowManageLibraryUI(libraryName, IntPtr.Zero,
    "CSWin7ShellLibrary", "Manage Library folders and settings", true);

向Shell Library中添加文件夹

SHAddFolderPathToLibrary可用来向指定的Shell Library中添加文件夹。

C++ AddFolderToShellLibrary

/**//*!
* Add a folder to an existing shell library.
*
* \param pShellLib
* The IShellLibrary interface of the shell library
*
* \param pwszFolderPath
* The path of the folder to be added into the shell library
*
* \param bSaveLocation
* If bSaveLocation is TRUE, set the folder as the save location of the shell
* library
*/
BOOL AddFolderToShellLibrary(IShellLibrary* pShellLib,
                             LPWSTR pwszFolderPath, BOOL bSaveLocation)
{
    HRESULT hr = SHAddFolderPathToLibrary(pShellLib, pwszFolderPath);
    if (FAILED(hr))
    {
        _tprintf(_T("SHAddFolderPathToLibrary failed to add a folder ") \
            _T("to the shell library w/err 0x%08lx\n"), hr);
        return FALSE;
    }

    // Save the folder as the save location of the shell library
    if (bSaveLocation)
    {
        // Create shell item from folder path
        IShellItem2* pShellItemSaveFolder = NULL;
        hr = SHCreateItemFromParsingName(pwszFolderPath, 0,
            IID_PPV_ARGS(&pShellItemSaveFolder));
        if (FAILED(hr))
        {
            _tprintf(_T("SHCreateItemFromParsingName failed w/err ") \
                _T("0x%08lx\n"), hr);
            return FALSE;
        }

        // Set the folder as the save location
        pShellLib->SetDefaultSaveFolder(DSFT_DETECT, pShellItemSaveFolder);
       
        if (pShellItemSaveFolder != NULL)
            pShellItemSaveFolder->Release();

        if (FAILED(hr))
        {
            _tprintf(_T("IShellLibrary::SetDefaultSaveFolder failed ") \
                _T("w/err 0x%08lx\n"), hr);
            return FALSE;
        }
    }

    // Commit the change of the shell library
    pShellLib->Commit();

    return TRUE;
}

上一页  1 2 3 4 5  下一页

Tags:Windows 特性 Shell

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