网站首页  词典首页

请输入您要查询的函数:

 

术语 shbrowseforfolder
释义 SHBrowseForFolder
语法:
PIDLIST_ABSOLUTE SHBrowseForFolder( LPBROWSEINFO lpbi
);
SHBrowseForFolder函数
显示一个对话框,使用户能够选择一个Shell文件夹。
参数
lpbi
[in]指向一个BROWSEINFO结构。传达的信息用于显示对话框。
返回值
返回一个指针,指向一个项目标识符列表(的PIDL),指定所选文件夹的位置相对于命名空间的根源。如果用户选择了在对话框中取消按钮,返回值为NULL。
这是可能是的PIDL返回的是一个文件夹的快捷方式,而不是一个文件夹。有关这一案件的全面讨论,请参见备注部分。
备注
对于Windows Vista或更高版本,则建议您使用FOS_PICKFOLDERS选择,而不是SHBrowseForFolder函数IFileDialog。这种使用模式中选择打开文件夹对话框,是首选的实施。
您必须初始化组件对象模型(COM),然后调用SHBrowseForFolder。如果您使用CoInitializeEx的初始化COM,您必须设置在dwCoInit参数COINIT_APARTMENTTHREADED标记。您也可以使用CoInitialize或OleInitialize的,它总是使用单元线程。如果您需要拖放拖放功能,OleInitialize的建议,因为它所需的OLE初始化,以及作为COM。
注意:如果使用的COM初始化与COINIT_MULTITHREADED标志CoInitializeEx的,SHBrowseForFolder失败如果调用应用程序使用在BROWSEINFO结构BIF_USENEWUI或BIF_NEWDIALOGSTYLE标志。
这是调用应用程序负责调用CoTaskMemFree自由的SHBrowseForFolder产生的IDList时,不再需要。
有两种样式对话框中可用。原来的老式显示默认情况下,不调整大小。较新的风格提供了额外的功能,包括拖动对话框内,重新排序,删除,快捷菜单,能够创建新的文件夹的拖放功能,以及其他快捷菜单命令。最初,它大于旧的对话框,但用户可以调整其大小。要指定一个对话框,使用的是新的风格,设置在BROWSEINFO结构ulFlags成员BIF_USENEWUI标志。
如果您实现一个回调函数,在BROWSEINFO结构lpfn成员中指定,您将收到一个句柄对话框。这方面的一个窗口句柄使用的是修改的布局或对话框的内容。因为它是不可调整大小,修改旧样式对话框相对来说比较简单。修改样式对话框中的新困难得多,而不是建议。它不仅有不同的大小比旧风格和布局,但其尺寸和其控制的立场都有所变化,是由用户大小的时间。
如果BIF_RETURNONLYFSDIRS标志在BROWSEINFO结构,确定按钮ulFlags成员设置仍启用“\\ \\服务器”项目,以及“\\ \\服务器\\共享”和目录的项目。但是,如果用户选择“\\ \\服务器”项目,通过的PIDL的SHBrowseForFolder返回SHGetPathFromIDList失败。
SHBrowseForFolder不显示库。
自定义过滤
作为Windows XP,SHBrowseForFolder支持自定义的对话框中的内容过滤。要创建自定义过滤器,请按照下列步骤。
设置在BROWSEINFO结构ulFlags成员BIF_NEWDIALOGSTYLE标志指向的lpbi参数。
指定在同一BROWSEINFO结构lpfn成员的回调函数。
代码的回调函数接收BFFM_INITIALIZED和BFFM_IUNKNOWN消息。论BFFM_IUNKNOWN消息后,回调函数的lParam参数包含一个指向对话框的IUnknown执行。调用QueryInterface该IUnknown获得一个指向的IFolderFilterSite实例。
创建一个对象实现IFolderFilter。
呼叫IFolderFilterSite::SetFilter,传递给它一个指向您的IFolderFilter。 IFolderFilter方法可以用来包含与排除从树上项目。
一旦创建过滤器,接口的IFolderFilterSite不再需要。呼叫IFolderFilterSite::发布,如果您没有这样的进一步使用。
处理快捷
注意:本节仅适用于Microsoft Windows 2000和以前的系统。默认情况下,Windows XP和更高版本的系统返回一个快捷方式的目标的PIDL,而不是快捷方式本身,只要BIF_NOTRANSLATETARGETS标志没有在BROWSEINFO结构设置。
如果SHBrowseForFolder返回的PIDL的快捷方式,发送到SHGetPathFromIDList说的PIDL返回快捷方式本身,而不是它的目标路径。到快捷方式的目标路径,可通过IShellLink接口作为显示在这个例子。
#include
// Macros for interface casts
#ifdef __cplusplus
#define IID_PPV_ARG(IType, ppType) IID_##IType, reinterpret_cast(static_cast(ppType))
#else
#define IID_PPV_ARG(IType, ppType) &IID_##IType, (void**)(ppType)
#endif
// Retrieves the UIObject interface for the specified full PIDL
STDAPI SHGetUIObjectFromFullPIDL(LPCITEMIDLIST pidl, HWND hwnd, REFIID riid, void **ppv)
{
LPCITEMIDLIST pidlChild;
IShellFolder* psf;
*ppv = NULL;
HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlChild);
if (SUCCEEDED(hr))
{
hr = psf->GetUIObjectOf(hwnd, 1, &pidlChild, riid, NULL, ppv);
psf->Release();
}
return hr;
}

#define ILSkip(pidl, cb) ((LPITEMIDLIST)(((BYTE*)(pidl))+cb))
#define ILNext(pidl) ILSkip(pidl, (pidl)->mkid.cb)

HRESULT SHILClone(LPCITEMIDLIST pidl, LPITEMIDLIST *ppidl)
{
DWORD cbTotal = 0;
if (pidl)
{
LPCITEMIDLIST pidl_temp = pidl;
cbTotal += sizeof (pidl_temp->mkid.cb);
while (pidl_temp->mkid.cb)
{
cbTotal += pidl_temp->mkid.cb;
pidl_temp += ILNext (pidl_temp);
}
}

*ppidl = (LPITEMIDLIST)CoTaskMemAlloc(cbTotal);

if (*ppidl)
CopyMemory(*ppidl, pidl, cbTotal);

return *ppidl ? S_OK: E_OUTOFMEMORY;
}

// Get the target PIDL for a folder PIDL. This also deals with cases of a folder
// shortcut or an alias to a real folder.
STDAPI SHGetTargetFolderIDList(LPCITEMIDLIST pidlFolder, LPITEMIDLIST *ppidl)
{
IShellLink *psl;
 
*ppidl = NULL;

HRESULT hr = SHGetUIObjectFromFullPIDL(pidlFolder, NULL, IID_PPV_ARG(IShellLink, &psl));

if (SUCCEEDED(hr))
{
hr = psl->GetIDList(ppidl);
psl->Release();
}

// It's not a folder shortcut so get the PIDL normally.
if (FAILED(hr))
hr = SHILClone(pidlFolder, ppidl);

return hr;
}
// Get the target folder for a folder PIDL. This deals with cases where a folder
// is an alias to a real folder, folder shortcuts, the My Documents folder, and
// other items of that nature.
STDAPI SHGetTargetFolderPath(LPCITEMIDLIST pidlFolder, LPWSTR pszPath, UINT cchPath)
{
LPITEMIDLIST pidlTarget;
 
*pszPath = 0;
HRESULT hr = SHGetTargetFolderIDList(pidlFolder, &pidlTarget);

if (SUCCEEDED(hr))
{
SHGetPathFromIDListW(pidlTarget, pszPath); // Make sure it is a path
CoTaskMemFree(pidlTarget);
}

return *pszPath ? S_OK : E_FAIL;
}
在Windows 95/98/Me:SHBrowseForFolder是支持的Unicode(MSLU)微软层。要使用此,您必须将某些文件到您的应用,概述了对Unicode的Microsoft层在Windows 95/98系统。
功能信息
最低DLL版本 shell32.dll 4.0或更高版本
自定义ImplementationNo
Headershlobj.h
import libraryshell32.lib
最低经营systemsWindows NT 4.0中,Windows 95中
UnicodeImplemented为ANSI和Unicode版本。
参见
打开和保存对话框
==英文原文==SHBrowseForFolder Function
Displays a dialog box that enables the user to select a Shell folder.
Syntax
PIDLIST_ABSOLUTE SHBrowseForFolder( LPBROWSEINFO lpbi
);
Parameters
lpbi
[in] A pointer to a BROWSEINFO structure. Conveys information used to display the dialog box.
Return Value
Returns a pointer to an item identifier list (PIDL) that specifies the location of the selected folder relative to the root of the namespace. If the user chooses the Cancel button in the dialog box, the return value is NULL.
It is possible that the PIDL returned is that of a folder shortcut rather than a folder. For a full discussion of this case, see the Remarks section.
Remarks
For Windows Vista or later, it is recommended that you use IFileDialog with the FOS_PICKFOLDERS option rather than the SHBrowseForFolder function. This uses the Open Files dialog in pick folders mode and is the preferred implementation.
You must initialize Component Object Model (COM) before you call SHBrowseForFolder. If you initialize COM using CoInitializeEx , you must set the COINIT_APARTMENTTHREADED flag in its dwCoInit parameter. You can also use CoInitialize or OleInitialize , which always use apartment threading. If you require drag-and-drop functionality, OleInitialize is recommended because it initializes the required OLE as well as COM.
Note If COM is initialized using CoInitializeEx with the COINIT_MULTITHREADED flag, SHBrowseForFolder fails if the calling application uses the BIF_USENEWUI or BIF_NEWDIALOGSTYLE flag in the BROWSEINFO structure.
It is the responsibility of the calling application to call CoTaskMemFree to free the IDList returned by SHBrowseForFolder when it is no longer needed.
There are two styles of dialog box available. The older style is displayed by default and is not resizable. The newer style provides a number of additional features, including drag-and-drop capability within the dialog box, reordering, deletion, shortcut menus, the ability to create new folders, and other shortcut menu commands. Initially, it is larger than the older dialog box, but the user can resize it. To specify a dialog box using the newer style, set the BIF_USENEWUI flag in the ulFlags member of the BROWSEINFO structure.
If you implement a callback function, specified in the lpfn member of the BROWSEINFO structure, you receive a handle to the dialog box. One use of this window handle is to modify the layout or contents of the dialog box. Because it is not resizable, modifying the older style dialog box is relatively straightforward. Modifying the newer style dialog box is much more difficult, and not recommended. Not only does it have a different size and layout than the old style, but its dimensions and the positions of its controls change every time it is resized by the user.
If the BIF_RETURNONLYFSDIRS flag is set in the ulFlags member of the BROWSEINFO structure, the OK button remains enabled for "\\\\server" items, as well as "\\\\server\\share" and directory items. However, if the user selects a "\\\\server" item, passing the PIDL returned by SHBrowseForFolder to SHGetPathFromIDList fails.
SHBrowseForFolder does not display libraries.
Custom Filtering
As of Windows XP, SHBrowseForFolder supports custom filtering on the contents of the dialog box. To create a custom filter, follow these steps.
Set the BIF_NEWDIALOGSTYLE flag in the ulFlags member of the BROWSEINFO structure pointed to by the lpbi parameter.
Specify a callback function in the lpfn member of that same BROWSEINFO structure.
Code the callback function to receive the BFFM_INITIALIZED and BFFM_IUNKNOWN messages. On receipt of the BFFM_IUNKNOWN message, the callback function's lParam parameter contains a pointer to the dialog box's implementation of IUnknown . Call QueryInterface on that IUnknown to obtain a pointer to an instance of IFolderFilterSite .
Create an object that implements IFolderFilter .
Call IFolderFilterSite::SetFilter , passing to it a pointer to your IFolderFilter. IFolderFilter methods can then be used to include and exclude items from the tree.
Once the filter is created, the IFolderFilterSite interface is no longer needed. Call IFolderFilterSite::Release if you have no further use for it.
Dealing With Shortcuts
Note This section applies to only Microsoft Windows 2000 and earlier systems. By default, Windows XP and later systems return the PIDL of a shortcut's target rather than the shortcut itself, as long as the BIF_NOTRANSLATETARGETS flag is not set in the BROWSEINFO structure.
If SHBrowseForFolder returns a PIDL to a shortcut, sending that PIDL to SHGetPathFromIDList returns the path of the shortcut itself rather than the path of its target. The path to the shortcut's target can be obtained by using the IShellLink interface as shown in this example.
#include
// Macros for interface casts
#ifdef __cplusplus
#define IID_PPV_ARG(IType, ppType) IID_##IType, reinterpret_cast(static_cast(ppType))
#else
#define IID_PPV_ARG(IType, ppType) &IID_##IType, (void**)(ppType)
#endif
// Retrieves the UIObject interface for the specified full PIDL
STDAPI SHGetUIObjectFromFullPIDL(LPCITEMIDLIST pidl, HWND hwnd, REFIID riid, void **ppv)
{
LPCITEMIDLIST pidlChild;
IShellFolder* psf;
*ppv = NULL;
HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlChild);
if (SUCCEEDED(hr))
{
hr = psf->GetUIObjectOf(hwnd, 1, &pidlChild, riid, NULL, ppv);
psf->Release();
}
return hr;
}

#define ILSkip(pidl, cb) ((LPITEMIDLIST)(((BYTE*)(pidl))+cb))
#define ILNext(pidl) ILSkip(pidl, (pidl)->mkid.cb)

HRESULT SHILClone(LPCITEMIDLIST pidl, LPITEMIDLIST *ppidl)
{
DWORD cbTotal = 0;
if (pidl)
{
LPCITEMIDLIST pidl_temp = pidl;
cbTotal += sizeof (pidl_temp->mkid.cb);
while (pidl_temp->mkid.cb)
{
cbTotal += pidl_temp->mkid.cb;
pidl_temp += ILNext (pidl_temp);
}
}

*ppidl = (LPITEMIDLIST)CoTaskMemAlloc(cbTotal);

if (*ppidl)
CopyMemory(*ppidl, pidl, cbTotal);

return *ppidl ? S_OK: E_OUTOFMEMORY;
}

// Get the target PIDL for a folder PIDL. This also deals with cases of a folder
// shortcut or an alias to a real folder.
STDAPI SHGetTargetFolderIDList(LPCITEMIDLIST pidlFolder, LPITEMIDLIST *ppidl)
{
IShellLink *psl;
 
*ppidl = NULL;

HRESULT hr = SHGetUIObjectFromFullPIDL(pidlFolder, NULL, IID_PPV_ARG(IShellLink, &psl));

if (SUCCEEDED(hr))
{
hr = psl->GetIDList(ppidl);
psl->Release();
}

// It's not a folder shortcut so get the PIDL normally.
if (FAILED(hr))
hr = SHILClone(pidlFolder, ppidl);

return hr;
}
// Get the target folder for a folder PIDL. This deals with cases where a folder
// is an alias to a real folder, folder shortcuts, the My Documents folder, and
// other items of that nature.
STDAPI SHGetTargetFolderPath(LPCITEMIDLIST pidlFolder, LPWSTR pszPath, UINT cchPath)
{
LPITEMIDLIST pidlTarget;
 
*pszPath = 0;
HRESULT hr = SHGetTargetFolderIDList(pidlFolder, &pidlTarget);

if (SUCCEEDED(hr))
{
SHGetPathFromIDListW(pidlTarget, pszPath); // Make sure it is a path
CoTaskMemFree(pidlTarget);
}

return *pszPath ? S_OK : E_FAIL;
}
Windows 95/98/Me: SHBrowseForFolder is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows Me/98/95 Systems .
Function Information
Minimum DLL Versionshell32.dll version 4.0 or later
Custom ImplementationNo
Headershlobj.h
Import libraryshell32.lib
Minimum operating systemsWindows NT 4.0, Windows 95
UnicodeImplemented as ANSI and Unicode versions.
See Also
Open and Save as Dialog Boxes
==原始网址==http://msdn.microsoft.com/en-us/library/bb762115(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:26:15