打开文件对话框的调用:
Void CsimpleDlg::OnFileOpen()
{
CFileDialog *lpszOpenFile; //定义一个CfileDialog对象
lpszOpenFile = new
CFileDialog(TRUE,””,””,OFN_FILEMUSTEXIST |OFN_HIDEREADONLY , “文件类型(*.yourfiletype)|*.yourfiletype||”);//生成一个对话框
if(lpzsOpenFile->DoModal() == ID_OK)//假如点击对话框确定按钮
{
CString szGetName;
szGetName = lpszOpenFile->GetPathName(); //得到打开文件的路径
SetWindowText(szGetName); //在窗口标题上显示路径
}
delete lpszOpenfile; //释放分配的对话框
}
对一些函数的解释:
CFileDialog(
BOOL bOpenFileDialog, //值为TRUE时表示”打开”对话框,值为FALSE时表”保存”对话框
LPCTSTR lpszDefExt = NULL, //默认的文件名扩张
LPCTSTR lpszFileName = NULL,
//打开对话框时默认出现在文本框里的文件名,为NULL时不显示默认文名
Dword dwFlags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST
//对文件属性等定义的组合,
LPCTSTR lpszFilter = NULL,//可以应用的文件类型,如*.MP3
CWnd* pParentWnd = NULL,
// A pointer to the file dialog-box object's parent or owner window.
DWORD dwSize = 0
/* The size of the OPENFILENAME structure. This value is dependent on the operating system version, so MFC can determine the appropriate kind of dialog to create (for example, new windows 2000 dialogs as opposed to NT4 dialogs). */
);
保存文件对话框和上面代码相似,只要把CfileDialog(TRUE,””,””…..)中的TRUE改为FALSE即可。