弹出带预览窗口的文件打开保存对话框
static CString DoPreviewFileDialog(BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL, LPCTSTR pszInitialDir = NULL);
参数 |
说明 |
BOOL bOpenFileDialog |
为true是打开文件对话框,为false是保存文件对话框 |
LPCTSTR lpszDefExt = NULL |
缺省的文件的扩展名 |
LPCTSTR lpszFileName = NULL |
缺省的文件名 |
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
对话的控制标志位,这个CFileDoialog中的dwFlags作用是一样的 |
LPCTSTR lpszFilter = NULL |
文件名的扩展名过滤表,详细参考MFC帮助中CFileDoialog说明 |
CWnd* pParentWnd = NULL |
打开保存对话框的父窗口 |
LPCTSTR pszInitialDir = NULL |
初始文件目录 |
成功返回得到文件路径,失败返回空字符串
x 例如:x
void CTestDlg::OpenDwgFile() { CString sAppPath; ::GetModuleFileName(NULL, sAppPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH); sAppPath.ReleaseBuffer(); int pos; pos=sAppPath.ReverseFind('\'); sAppPath=sAppPath.Left(pos); // 得到初始目录路径 CString sInitialDir = AfxGetApp()->GetProfileString(_T("MxDWGTestDlg"),_T("OpenDir"),sAppPath ); CTestDlg* pDlg = (CTestDlg*)AfxGetApp()->GetMainWnd(); // 弹出打开dwg文件对话框 CString sFileName = MxDraw::DoPreviewFileDialog(TRUE, _T("dwg"),NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("DWG files (*.dwg)|*.dwg|DXF files (*.dxf)|*.dxf||"), pDlg, sInitialDir ); if(sFileName.IsEmpty() ) return; int iFindPos = sFileName.ReverseFind('\'); if(iFindPos >= 0) { CString sPath = sFileName.Left(iFindPos + 1); AfxGetApp()->WriteProfileString(_T("MxDWGTestDlg"),_T("OpenDir"),sPath); CString sTitle = sFileName.Right(sFileName.GetLength() - iFindPos - 1); pDlg->SetWindowText(sTitle); } if(!MxDraw::ReadDwg(pDlg->m_hDrawOcx,sFileName) ) { CString sError; sError.Format(_T("打开dwg文件%s失败"),sFileName); AfxMessageBox(sError); } }