#include "stdafx.h" #include ".\filebrowse.h" CFileBrowse::CFileBrowse(void) { CfgFileFilter = _T("Configuration Files (*.txt)|*.txt|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"); TxtFileFilter = _T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"); ExeFileFilter = _T("Programs (*.exe)|*.exe|All Files (*.*)|*.*||"); BmpFileFilter = _T("Windows Bitmap (*.bmp)|*.bmp|All Files (*.*)|*.*||"); McaFileFilter = _T("Spectra Data Files (*.mca)|*.mca|All Files (*.*)|*.*||"); LibFileFilter = _T("Library Files (*.lib)|*.lib|All Files (*.*)|*.*||"); AllFileFilter = _T("All Files (*.*)|*.*||"); } CFileBrowse::~CFileBrowse(void) { } BOOL CFileBrowse::DoModal(int DlgType, CString DlgTitle, CString FileFilter, CString DefaultExt, CString InitDir, CString* Filename) { BOOL bResult = FALSE; CString strFilter(""); CString strExtension(""); DWORD dwFlags = 0; if (FileFilter.GetLength() > 1) { strFilter = FileFilter; } if (DefaultExt.GetLength() > 1) { strExtension = DefaultExt; } dwFlags = (DlgType) ? OFN_FILEMUSTEXIST : OFN_OVERWRITEPROMPT; dwFlags |= OFN_HIDEREADONLY; dwFlags |= OFN_ENABLESIZING; dwFlags &= ~OFN_CREATEPROMPT; //prevent forced file creation on open CFileDialog FileDlg(DlgType, strExtension, (*Filename), dwFlags, strFilter); FileDlg.m_ofn.lpstrTitle = DlgTitle; if (InitDir.GetLength() > 1) { FileDlg.m_ofn.lpstrInitialDir = InitDir; } if (FileDlg.DoModal() == IDOK) { bResult = TRUE; *Filename = FileDlg.GetPathName(); } return bResult; }