I'm trying to build an MFC SDI (Single-Document Interface) application with these requirements:
Show only one document at a time.
Support different views based on the file type chosen from the file open dialog. For example, if a *.txt file is chosen, I would show MyCViewText, while I would show MyCViewImage if a *.jpg file is chosen.
Show a custom list of file extensions file open dialog. For example, use a custom dialog and filter like:
CFileDialog *dlg = new CFileDialog(TRUE, NULL, NULL, NULL, L"Text Files (*.txt)|*.txt|" L"JPEG Files (*.jpg)|*.jpg||");
But, I have two problems.
First, I don't know where to insert the file extensions filter for the File -> Open dialog. If I override CWinApp::OnFileOpen()
with a custom CFileDialog
, then I lose all the behind-the-scenes behavior that the SDI provides, like invoking the CDocument::OnDocumentOpen()
call and initializing the document template's CView. I can't call CWinApp::OnFileOpen()
in the override because a second file open dialog appears after the first and without the file extensions filter.
Second, I don't know where to insert the view toggle code after a file has been chosen from the file open dialog. The document template is set up like this:
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMyAppDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CMyCView));
It seems like I would want to override CWinApp::OnFileOpen()
and switch the document template view RUNTIME_CLASS (CMyCView), but I'm not sure this is even possible.
Is the MFC SDI just not suited for my three requirements? Do I have to use an MFC MDI application instead? If I have to somehow use MDI, then how would I restrict to only having a single document loaded and shown at any given time?
Any help is appreciated.