- 浏览: 153629 次
- 性别:
- 来自: 沈阳
文章分类
最新评论
-
gybin:
这只是一部分, 更多情况是 资源也有,编译也通过了,是在运行 ...
android.view.InflateException: Binary XML file line #...Error inflating class .. -
hanyezhiyu8:
zhaorongrong0720 写道你好,有问题想问你,我现 ...
Mysql与MysqlODBC连接错误:Client does not support authentication protocol requested... -
zhaorongrong0720:
你好,有问题想问你,我现在出现了同样的错误,请问你所写的解决办 ...
Mysql与MysqlODBC连接错误:Client does not support authentication protocol requested... -
hanyezhiyu8:
onAccuracyChanged飞扬云 写道onAccura ...
Android 传感器 Sensor -
飞扬云:
onAccuracyChanged:你提到这个传感器的新的准确 ...
Android 传感器 Sensor
1. 标准的文件夹选择对话框:可以使用在非MFC程序中,调用的标准API SHBrowserForFolder。
源码:
#include "shlobj.h" #include <STRING> // Function name : GetFolder // Description : Open and get Folder Dialog. // Return type : true means click ok, false mean no select and cancel. // Argument : folder path reference // Argument : dialog window caption // Argument : parent window handle bool GetFolder(std::string& folderpath, const char* szCaption = NULL, HWND hOwner = NULL) { bool retVal = false; // The BROWSEINFO struct tells the shell // how it should display the dialog. BROWSEINFO bi; memset(&bi, 0, sizeof(bi)); bi.ulFlags = BIF_USENEWUI; bi.hwndOwner = hOwner; bi.lpszTitle = szCaption; // must call this if using BIF_USENEWUI ::OleInitialize(NULL); // Show the dialog and get the itemIDList for the selected folder. LPITEMIDLIST pIDL = ::SHBrowseForFolder(&bi); if(pIDL != NULL) { // Create a buffer to store the path, then get the path. char buffer[_MAX_PATH] = {'\0'}; if(::SHGetPathFromIDList(pIDL, buffer) != 0) { // Set the string value. folderpath = buffer; retVal = true; } // free the item id list CoTaskMemFree(pIDL); } ::OleUninitialize(); return retVal; }
调用:
std::string szPath(""); if (GetFolder(szPath, "Select a folder.") == true) { printf("You selected: \"%s\".\n", szPath.c_str()); } else { printf("No folder selected!\n"); }
界面:
2. 带导航栏的文件夹选择对话框:只在MFC程序中使用,从MFC的CFileDialog派生。
源码-头文件-Folder_dialog.h:
#pragma once // CFolderDialog dialog class CFolderDialog : public CFileDialog { DECLARE_DYNAMIC(CFolderDialog) public: CFolderDialog(CString* pPath, CWnd* pParentWnd = NULL); static WNDPROC m_wndProc; CString* m_pPath; protected: DECLARE_MESSAGE_MAP() private: virtual void OnInitDone(); virtual void OnFileNameChange(); virtual void OnFolderChange(); void ChangeFolder(); };
源码-Folder_dialog.cpp:
#include "stdafx.h" #include "folder_dialog.h" #include <DLGS.H> #include <WINUSER.H> #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // CFolderDialog IMPLEMENT_DYNAMIC(CFolderDialog, CFileDialog) WNDPROC CFolderDialog::m_wndProc = NULL; // Function name : CFolderDialog::CFolderDialog // Description : Constructor // Return type : // Argument : CString* pPath ; represent string where selected folder wil be saved CFolderDialog::CFolderDialog(CString* pPath, CWnd* pParentWnd) : CFileDialog(true, NULL, _T("*..*"), 6UL, NULL, pParentWnd) { m_pPath = pPath; } BEGIN_MESSAGE_MAP(CFolderDialog, CFileDialog) END_MESSAGE_MAP() // Function name : WindowProcNew // Description : Call this function when user navigate into CFileDialog. // Return type : LRESULT // Argument : HWND hwnd // Argument : UINT message // Argument : WPARAM wParam // Argument : LPARAM lParam LRESULT CALLBACK WindowProcNew(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { if(message == WM_COMMAND) { if(HIWORD(wParam) == BN_CLICKED) { if(LOWORD(wParam) == IDOK) { if(CFileDialog* pDlg = (CFileDialog*)CWnd::FromHandle(hwnd)) { TCHAR path[MAX_PATH]; GetCurrentDirectory(MAX_PATH, path); *((CFolderDialog*)pDlg->GetDlgItem(0))->m_pPath = CString(path); pDlg->EndDialog(IDOK); return NULL; } } } } return CallWindowProc(CFolderDialog::m_wndProc, hwnd, message, wParam, lParam); } // Function name : CFolderDialog::OnInitDone // Description : For update the wiew of CFileDialog // Return type : void void CFolderDialog::OnInitDone() { HideControl(edt1); //HideControl(stc3); //Select file static text //HideControl(cmb13); //Current file combobox HideControl(cmb1); //File filter combobox HideControl(stc2); //Filter static text //Rearrange the controls in the bottom. CWnd* pFD = GetParent(); //Get Cancel Button Position CRect rectCancel; pFD->GetDlgItem(IDCANCEL)->GetWindowRect(rectCancel); pFD->ScreenToClient(rectCancel); //Enlarge Listview control CRect rectList2; pFD->GetDlgItem(lst1)->GetWindowRect(rectList2); pFD->ScreenToClient(rectList2); pFD->GetDlgItem(lst1)->SetWindowPos(0, 0, 0, rectList2.Width(), abs(rectList2.top - (rectCancel.top - 4)), SWP_NOMOVE | SWP_NOZORDER); //Set Static text and position CRect rectText; pFD->GetDlgItem(stc3)->GetWindowRect(rectText); pFD->ScreenToClient(rectText); pFD->GetDlgItem(stc3)->SetWindowPos(0, rectList2.left, rectCancel.top + 6, 0, 0, SWP_NOZORDER | SWP_NOSIZE); SetControlText(stc3, _T("Selected:")); //ComboBox of current file CRect rectComBo; pFD->GetDlgItem(cmb13)->GetWindowRect(rectComBo); pFD->ScreenToClient(rectComBo); pFD->GetDlgItem(cmb13)->SetWindowPos(0, rectText.left + rectText.Width() - 40, rectCancel.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); //Set OK Button Position CRect rectOK; pFD->GetDlgItem(IDOK)->GetWindowRect(rectOK); pFD->ScreenToClient(rectOK); pFD->GetDlgItem(IDOK)->SetWindowPos(0, rectCancel.left - rectOK.Width() - 2, rectCancel.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); SetControlText(IDOK, _T("Select")); pFD->SetWindowText(_T("Choose folder")); pFD->CenterWindow(); m_wndProc = (WNDPROC)SetWindowLong(pFD->m_hWnd, GWL_WNDPROC, (long)WindowProcNew); } //Change the combobox context when select folder. void CFolderDialog::OnFileNameChange() { ChangeFolder(); } //If the folder contains no sub folder, the OnFileNameChange will not be triggered. //Add this OnFolderChange to double sure even if there is no sub folder. void CFolderDialog::OnFolderChange() { ChangeFolder(); } //Change the combobox text to current selected folder void CFolderDialog::ChangeFolder() { TCHAR path[MAX_PATH] = {0}; GetCurrentDirectory(MAX_PATH, path); SetControlText(cmb13, path); }
调用:
CString folderPath; CFolderDialog dlg(&folderPath, this); if(IDOK == dlg.DoModal()) { UpdateData(false); }
链接:http://www.vckbase.com/english/code/dialog/folder_dialog.shtml.htm
3. 复杂的但是功能比较全的窗口XFolderDialog:
界面:
链接:http://www.codeproject.com/KB/dialog/XFolderDialog.aspx
发表评论
-
VC中处理命令行参数:GetCommandLine()与m_lpCmdLine
2012-08-28 14:08 7557對於VC程序无论是SDI、MDI还是基于Dialog的程序,主 ... -
c++高级编程笔记
2011-10-29 11:10 4a -
offce自动化编程操作word、ppt、excel时,使用application的createdispatch等操作,产生错误
2011-09-16 14:18 1500offce自动化编程操作word、ppt、excel时,使用a ... -
Sensor驱动:Location API 取不到GPS经纬度等数据或不识别传感器
2011-06-21 14:40 1405---------------------------- ... -
ShellExecute : 同步启动一个进程,等待结束
2011-04-18 20:22 4732---------------------------- ... -
HTTPS 证书处理
2011-04-09 11:36 1093---------------------------- ... -
关于Mutex的使用问题
2011-01-04 18:44 7452权限问题 互斥量对象会一直存活着直到使用它的最后一个程 ... -
ASC编码和Unicode编码之间转换
2010-12-27 13:33 19811. ASC编码转Unicode编码 void Con ... -
CDialog::Create时使窗体失去焦点
2010-12-24 11:49 1422//在OnInitDialog()中: ModifySt ... -
计算数组大小_countof
2010-12-19 18:54 1791_countof 是 C++中计算一个固定大小数组长度的宏: ... -
Volatile
2010-12-15 11:25 823volatile [ˈvɔlətail] adj. ... -
CFileFind类
2010-12-14 03:49 1736一、注意: 1、CFileFind类的声明文件 ... -
VC中删除文件夹中内容
2010-12-12 20:37 1599方法一:(MFC) BOOL DeleteDirectory ... -
获取当前用户的SID
2010-12-12 16:45 3005方法一: BOOL GetSID(CString& ... -
ExpandEnvironmentStrings扩展系统变量
2010-12-12 16:13 1408CString csFilePathName; ::Expa ... -
WTSRegisterSessionNotification
2010-12-12 16:06 1232cdialog中 配置WTSRegisterSessionN ... -
利用高精度计时器计算程序运行时间
2010-12-12 12:57 1858QueryPerformanceFrequency() 类型 ... -
CWnd与HWND的区别与转换
2010-12-10 16:31 2823一、区别HWND是句柄,CWnd是MFC窗体类,CWnd中包含 ... -
CStdioFile
2010-12-09 14:20 1623CFile//创建/打开文件CFile ... -
c++/vc产生随机数
2010-12-04 16:18 1837int GenerateRandomNumber(int ra ...
相关推荐
QQ发送文件夹/文件混合对话框的实现, 是基于新系统的新样式的 是对话框的功能部分与发送什么的没关系 按CTRL多选,可以同时选择多个文件/文件夹 VS2015环境下 WIN8测试正常
WPF:自定义Metro样式文件夹选择对话框FolderBrowserDialog
delphi 文件夹选择对话框(带新建文件夹) 控件 我自已写的,争点分!
选择目录 选择文件 对话框 vs2010 具体描述在blog: http://blog.csdn.net/cau_eric/article/details/12570815
VC++, MFC中实现选择文件夹,选择文件对话框,确定当前工作目录
Qt QFileDialog 文件选择对话框 多选
MFC中有CFileDialog但是没有CFolderDialog,这个类实现了选择文件夹路径的功能。 这个类是为我的上传下载工具而写。
打开文件夹对话框.打开文件夹对话框.打开文件夹对话框.打开文件夹对话框.
PlacesBar Editor 给自己的“打开/保存”对话框增加常用文件夹按钮!
WPF自带选择文件夹对话框较简单,且不支持快捷方式跳转。 本示例运行效果同window系统的资源管理器相似。 本代码初始来源于网络。部分我做了修改。 纯为了赚点资源分,好下载资料用。
工程里列举了常用对话框的创建方法,如保存对话框,文件夹选择对话框,文件选择对话框
visual c++ VC选择目录的对话框
文件文件夹多选对话框。基于MFC的文件选择对话框进行的改造,实现了同时选择多个文件和文件夹的...对于在系统虚拟目录“库”文件夹中进行选择文件和文件夹也做了特殊的处理。 在其他语言(比如c#)中也可以方便调用。
选择文件夹对话框 选择文件夹对话框 选择文件夹对话框
visual c++ vc在文件夹浏览对话框上加一个新建文件夹按钮
文件夹(路径)浏览对话框 <br>//浏览文件夹 //strCaption 标题 //strInit 初始化路径 //strRoot 根路径 //uFlags 标记 //strFilter 文件类型 当uFlags 包含BIF_BROWSEINCLUDEFILES时显示文件 ...
用GetOpenFileName 文件选择对话框实现既可以选择文件,又可以选择目录(文件夹)。
文件文件夹多选对话框。基于MFC的文件选择对话框进行的改造,实现了同时选择多个文件和文件夹的...对于在系统虚拟目录“库”文件夹中进行选择文件和文件夹也做了特殊的处理。 在其他语言(比如c#)中也可以方便调用。
,自己加个界面就和极品私人密盘一模一样了,具体原理请看源码,所有操作使用unicode版的API,顺便附送一个unicode版的文件/文件夹/通用对话框操作模块。 原理 其实就是用W版的API在回收站内创建畸形目录,使用时...
C语言用SHBrowseForFolder弹出选择文件夹的对话框