利用SHBrowseForFolder 产生 路径/文件夹 选择对话框 显示 创建文件夹
来源:互联网 发布:windows bat脚本 copy 编辑:程序博客网 时间:2024/06/05 05:57
前一篇文章中讲到了,如何通过SHBrowserForFolder来产生 路径/文件夹 选择对话框。
很多时候,我们除了需要选择文件夹之外,还希望可以随时随地的创建新的文件夹,这就要求选择的同时也可以创建,
SHBrowserForFolder提供了这样的选项
在产生 路径/文件夹 选择对话框时,我们可以通过设置BROWSEINFO的ulFlags来显示创建新文件夹的按钮,
以便于随时随地创建新窗口。
具体为:
br.ulFlags 添加以下标志位: BIF_USENEWUI。Shell and Common Controls Versions需要5.0及以后版本
br.ulFlags
Flags specifying the options for the dialog box. This member can include zero or a combination of the following values.
- BIF_BROWSEFORCOMPUTER
- Only return computers. If the user selects anything other than a computer, the OK button is grayed.
- BIF_BROWSEFORPRINTER
- Only allow the selection of printers. If the user selects anything other than a printer, the OK button is grayed.
In Microsoft Windows XP, the best practice is to use an XP-style dialog, setting the root of the dialog to the Printers and Faxes folder (CSIDL_PRINTERS).
- BIF_BROWSEINCLUDEFILES
- Version 4.71. The browse dialog box will display files as well as folders.
- BIF_BROWSEINCLUDEURLS
- Version 5.0. The browse dialog box can display URLs. The BIF_USENEWUI and BIF_BROWSEINCLUDEFILES flags must also be set. If these three flags are not set, the browser dialog box will reject URLs. Even when these flags are set, the browse dialog box will only display URLs if the folder that contains the selected item supports them. When the folder's IShellFolder::GetAttributesOf method is called to request the selected item's attributes, the folder must set the SFGAO_FOLDER attribute flag. Otherwise, the browse dialog box will not display the URL.
- BIF_DONTGOBELOWDOMAIN
- Do not include network folders below the domain level in the dialog box's tree view control.
- BIF_EDITBOX
- Version 4.71. Include an edit control in the browse dialog box that allows the user to type the name of an item.
- BIF_NEWDIALOGSTYLE
- Version 5.0. Use the new user interface. Setting this flag provides the user with a larger dialog box that can be resized. The dialog box has several new capabilities including: drag-and-drop capability within the dialog box, reordering, shortcut menus, new folders, delete, and other shortcut menu commands. To use this flag, you must call OleInitialize or CoInitialize before calling SHBrowseForFolder.
- BIF_NONEWFOLDERBUTTON
- Version 6.0. Do not include the New Folder button in the browse dialog box.
- BIF_NOTRANSLATETARGETS
- Version 6.0. When the selected item is a shortcut, return the PIDL of the shortcut itself rather than its target.
- BIF_RETURNFSANCESTORS
- Only return file system ancestors. An ancestor is a subfolder that is beneath the root folder in the namespace hierarchy. If the user selects an ancestor of the root folder that is not part of the file system, the OK button is grayed.
- BIF_RETURNONLYFSDIRS
- Only return file system directories. If the user selects folders that are not part of the file system, the OK button is grayed.
- BIF_SHAREABLE
- Version 5.0. The browse dialog box can display shareable resources on remote systems. It is intended for applications that want to expose remote shares on a local system. The BIF_NEWDIALOGSTYLE flag must also be set.
- BIF_STATUSTEXT
- Include a status area in the dialog box. The callback function can set the status text by sending messages to the dialog box. This flag is not supported when BIF_NEWDIALOGSTYLE is specified.
- BIF_UAHINT
- Version 6.0. When combined with BIF_NEWDIALOGSTYLE, adds a usage hint to the dialog box in place of the edit box. BIF_EDITBOX overrides this flag.
- BIF_USENEWUI
- Version 5.0. Use the new user interface, including an edit box. This flag is equivalent to BIF_EDITBOX | BIF_NEWDIALOGSTYLE. To use BIF_USENEWUI, you must call OleInitialize or CoInitialize before calling SHBrowseForFolder.
- BIF_VALIDATE
- Version 4.71. If the user types an invalid name into the edit box, the browse dialog box will call the application's BrowseCallbackProc with the BFFM_VALIDATEFAILED message. This flag is ignored if BIF_EDITBOX is not specified.
对上一篇文章中的步骤 二, 修改为以下格式即可:
TCHAR szDefaultDir[MAX_PATH];
CString strDef(_T("C://WINDOWS//"));
memcpy(szDefaultDir,strDef.GetBuffer(strDef.GetLength()),strDef.GetLength());
strDef.ReleaseBuffer();
TCHAR szPath[MAX_PATH];
BROWSEINFO br;
ITEMIDLIST* pItem;
br.hwndOwner = this->GetSafeHwnd();
br.pidlRoot = 0;
br.pszDisplayName = 0;
br.lpszTitle = "选择路径";
br.ulFlags = BIF_STATUSTEXT | BIF_USENEWUI;
br.lpfn = BrowseCallbackProc ; //设置CALLBACK函数
br.iImage = 0;
br.lParam = long(&szDefaultDir); //设置默认路径
//**转者注: 在Unicode环境下,编译测试,此处的默认路径无法起作用
//** 需要手动转换成TChar/WChar
//** TChar strBuffer[MAX_PATH];
//** wcscpy(strBuffer, szDefaultDir);
pItem = SHBrowseForFolder(&br);
if(pItem != NULL)
{
if(SHGetPathFromIDList(pItem,szPath) == TRUE)
{
CString strDir = szPath;
}
}
- 利用SHBrowseForFolder 产生 路径/文件夹 选择对话框 显示 创建文件夹
- zz:利用SHBrowseForFolder 产生路径选择对话框 同时指向默认路径文件夹
- VC选择文件夹路径对话框 - SHBrowseForFolder 函数
- 利用SHBrowseForFolder 产生路径选择对话框 同时指向默认路径文件
- SHBrowseForFolder(选择文件夹)
- 选择文件夹 SHBrowseForFolder
- SHBrowseForFolder弹出的选择文件夹对话框改变默认title
- 创建文件夹,选择路径
- MFC选择文件夹对话框,选择文件路径
- 转载:浏览文件夹对话框,演示SHBrowseForFolder用法
- 浏览文件夹对话框,演示SHBrowseForFolder用法
- 使用SHBrowseForFolder取得文件夹路径的例子
- SHBrowseForFolder象CFileDialog一样获取文件夹路径
- [vc++]使用SHBrowseForFolder获取文件夹路径
- 显示“选择文件夹”对话框,让用户选择文件夹
- Vb2010 弹出对话框来选择文件夹路径
- 调用系统对话框,选择指定文件夹路径
- 如何弹出一个选择文件夹路径的对话框选择路径?
- 自动化测试实施步骤和最佳实践
- 大师,你在哪里
- 解决直接打开Word 2003 慢
- 《Velocity 模板使用指南》中文版
- 如何使IE 8 支持eWebEditorExt编辑器
- 利用SHBrowseForFolder 产生 路径/文件夹 选择对话框 显示 创建文件夹
- 如何使用3dmax导出插件导出模型信息
- Java 中Vector、ArrayList和LinkedList 的区别
- 第一篇:“大集中”应用系统的结构和技术特点4——多线程和单线程的统一
- 专业Magento主机,每月仅30多块!
- 查看哪个端口被占用
- IE中取anchor
- 内核同步机制-信号量
- 堆排序--weis