通常是左侧有一个Edit控件,右侧有一个Button,在Button的相应里面调用CFileDialog用来选择文件。
步骤:
1)给Edit控件添加变量: m_FilePath;
2) 给Button的Click添加相应函数:
void CInDlgDlg::OnButton2()
{
char szFilters[]=
"MyType Files (*.txt)|*.txt|All Files (*.*)|*.*||";
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (TRUE, "txt"*.txt",
OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal()==IDOK )
{
CString pathName = fileDlg.GetPathName();
m_FilePath = pathName;
UpdateData(FALSE);
}
}