浏览按钮

//浏览文件夹

void CUpdateTestDlg::OnBnClickedBtnDzhpath()

{
CString strRetPach;
TCHAR szPath[MAX_PATH];
BROWSEINFO bi;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.lpszTitle = _T("文件夹浏览框");
bi.pszDisplayName = szPath;
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = NULL;
LPITEMIDLIST pItemIDList = SHBrowseForFolder(&bi);
if(pItemIDList)
{
if(SHGetPathFromIDList(pItemIDList, szPath))
strRetPach = szPath;
}
else
strRetPach = "";
((CEdit*)GetDlgItem(IDC_EDT_DZHPATH))->SetWindowText(strRetPach);

}

//浏览文件

void CShortKeySmokeTestDlg::OnBnClickedBtnOpen()
{
CString filter = "excel文件|*.xls|*.et";
CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,filter);
if(dlg.DoModal()==IDOK)
{
CString str = dlg.GetPathName();
CEdit *p_Edit = (CEdit*)GetDlgItem(IDC_EDT_EXCELFILE);
p_Edit ->SetWindowText(str);
}
}

你可能感兴趣的:(文件操作)