/*******************************************************************************
函数名称:FicowGetDirectory
函数说明:打开文件系统
输入参数:
无
输出参数:
无
返 回 值:
CString :选择的文件路径
作 者:lijilei
修改日期:2019-8-1
修改说明:基础版本
*******************************************************************************/
CString FicowGetDirectory()
{
BROWSEINFO bi;
char name[MAX_PATH];
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
bi.pszDisplayName = name;
bi.lpszTitle = "选择文件夹目录";
bi.ulFlags = BIF_RETURNFSANCESTORS;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if (idl == NULL)
return "";
CString strDirectoryPath;
SHGetPathFromIDList(idl, strDirectoryPath.GetBuffer(MAX_PATH));
strDirectoryPath.ReleaseBuffer();
if (strDirectoryPath.IsEmpty())
return "";
if (strDirectoryPath.Right(1) != "\\")
strDirectoryPath += "\\";
return strDirectoryPath;
}
void CMFC_hejia_gwqDlg::OnBnClickedSelect() //选择
{
CString fileRoute = FicowGetDirectory();
m_edit1 = fileRoute;
UpdateData(false); //将程序中改变的变量的值更新至控件中去
}
代码中m_edit1是edit控件添加的cstring类型值变量名称,OnBnClickedSelect函数为按钮单击事件函数
示例:
图一
图二
图三