Click here to Skip to main content
16,010,876 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Synchronize Pin
Christian Graus18-Nov-01 13:52
protectorChristian Graus18-Nov-01 13:52 
GeneralRe: Synchronize Pin
26-Mar-02 10:04
suss26-Mar-02 10:04 
GeneralDisplay Command line Pin
17-Nov-01 16:18
suss17-Nov-01 16:18 
GeneralRe: Display Command line Pin
Wolfram Steinke17-Nov-01 23:08
Wolfram Steinke17-Nov-01 23:08 
GeneralMFC opening files; creating a new view/doc Pin
robbied17-Nov-01 12:29
robbied17-Nov-01 12:29 
GeneralRe: MFC opening files; creating a new view/doc Pin
Christian Graus18-Nov-01 0:56
protectorChristian Graus18-Nov-01 0:56 
GeneralRe: MFC opening files; creating a new view/doc Pin
robbied18-Nov-01 6:22
robbied18-Nov-01 6:22 
GeneralRe: MFC opening files; creating a new view/doc Pin
Christian Graus18-Nov-01 10:24
protectorChristian Graus18-Nov-01 10:24 
Opening a document also creates a view to go with it.

To open a document from the mainframe class ( which I do to impliment a file browser ), I do this

AfxGetApp()->OpenDocumentFile(Dlg.m_Path);


where m_Path is a member variable of the browser dialog, containing the path to load

In my document class I override OnFileOpen and call it in the CWinApp derived class, which looks like this:

CDocument* CMyApp::OpenDocumentFile(LPCTSTR lpszFileName) 
{
	CFileStatus fs;
	if (!CFile::GetStatus(lpszFileName,fs))
	{
		CString s;
		s.Format("Error - file %s not found",lpszFileName);
		AfxMessageBox(s,MB_ICONERROR);
		return NULL;
	}
	try
	{
		CDocument* pReturn = CWinApp::OpenDocumentFile(lpszFileName);
		CMyDoc* pDoc = (CMyDoc*)pReturn;
		pDoc->m_Filename = lpszFileName;
		return pReturn;
	}
	catch(...)
	{
		return NULL;
	}
}


I seem to recall this was because it's a MDI app, so it called the method in CWinApp if I had nothing open, otherwise it called it in the document class.

This calls OnOpenDocument in my document class, where I simply load my data into the class and return TRUE. This gives me a document and the view associated with it.


Christian

After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
GeneralRe: MFC opening files; creating a new view/doc Pin
robbied18-Nov-01 16:03
robbied18-Nov-01 16:03 
GeneralRe: MFC opening files; creating a new view/doc Pin
Christian Graus18-Nov-01 16:26
protectorChristian Graus18-Nov-01 16:26 
GeneralRe: MFC opening files; creating a new view/doc Pin
robbied19-Nov-01 7:29
robbied19-Nov-01 7:29 
GeneralHeapFree is very very slow Pin
17-Nov-01 12:24
suss17-Nov-01 12:24 
GeneralChanging dialog bar font (after creation) Pin
User 988517-Nov-01 9:06
User 988517-Nov-01 9:06 
GeneralDIB_PAL_COLORS Question Pin
AJ12317-Nov-01 7:04
AJ12317-Nov-01 7:04 
Generalshow txt file Pin
mazy17-Nov-01 6:34
mazy17-Nov-01 6:34 
GeneralRe: show txt file Pin
Anders Molin17-Nov-01 6:41
professionalAnders Molin17-Nov-01 6:41 
GeneralRe: show txt file Pin
mazy17-Nov-01 7:23
mazy17-Nov-01 7:23 
GeneralRe: show txt file Pin
Anders Molin17-Nov-01 9:31
professionalAnders Molin17-Nov-01 9:31 
GeneralRe: show txt file Pin
Carlos Antollini19-Nov-01 8:11
Carlos Antollini19-Nov-01 8:11 
GeneralRe: show txt file Pin
Michael Dunn17-Nov-01 9:06
sitebuilderMichael Dunn17-Nov-01 9:06 
GeneralRe: show txt file Pin
Bill Wilson19-Nov-01 8:04
Bill Wilson19-Nov-01 8:04 
Generalget a pointer to the document Pin
sport17-Nov-01 5:25
sport17-Nov-01 5:25 
GeneralRe: get a pointer to the document Pin
Christian Skovdal Andersen17-Nov-01 5:57
Christian Skovdal Andersen17-Nov-01 5:57 
GeneralRe: get a pointer to the document Pin
sport17-Nov-01 9:21
sport17-Nov-01 9:21 
GeneralRe: get a pointer to the document Pin
Christian Skovdal Andersen17-Nov-01 23:39
Christian Skovdal Andersen17-Nov-01 23:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.