shmuelal
asked on
How to open programmatically a new file in an MDI application?
Hi all,
I'm writing an MDI application which is a visual studio like.
I want to open a new file through the tree view, and therefore I should handle this through the code.
The problem I have is how to open a new file in which I will put the content of the file I'm openning.
Thanks in advance,
Alon Shmuel
I'm writing an MDI application which is a visual studio like.
I want to open a new file through the tree view, and therefore I should handle this through the code.
The problem I have is how to open a new file in which I will put the content of the file I'm openning.
Thanks in advance,
Alon Shmuel
if u meant something else plz tell me.
hope it worx
hope it worx
ASKER
Hi,
What I ment is to open a new child window, like it happens when you select through the menu File->New.
What I ment is to open a new child window, like it happens when you select through the menu File->New.
um, okay one more thing, is your program is for text only? i mean, you want 2 make it like notepad or such programs?
if so u can change the base class from the beginning to CEditView, so? u wanna make it a text program?
if so u can change the base class from the beginning to CEditView, so? u wanna make it a text program?
If you want to open a new child window (with a new view on it) you should use the doc-template mechanism.
Meaning: create a new doc template and add it to the application. Than call OpenDocumentFile on the doc template.
If you need more information or source code - let me know.
Meaning: create a new doc template and add it to the application. Than call OpenDocumentFile on the doc template.
If you need more information or source code - let me know.
ASKER
First,
I'm using a Rich Edit View and therefore my view class is from that type.
regarding the doc-template thing.
I saw something about it at the MSDN but I didn't succeed in implementing it.
I would be very happy for an example.
Thanks
I'm using a Rich Edit View and therefore my view class is from that type.
regarding the doc-template thing.
I saw something about it at the MSDN but I didn't succeed in implementing it.
I would be very happy for an example.
Thanks
You can try something like this:
(In your CWinApp child InitInstance() you have someththing like:
pDocTemplate = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMAMReportsD oc),
RUNTIME_CLASS(CChildFrame) , // custom MDI child frame
RUNTIME_CLASS(CMAMReportsV iew));
AddDocTemplate(pDocTemplat e);
You can add a function to your tree control, like:
CMyDocument *CMyTreeControl::MakeDocum ent()
{
CMyDocument *WorkWinApp = (CMyWinApp *)AfxGetApp();
return (CMyDocument *)WorkWinApp->pDocTemplate ->OpenDocu mentFile(N ULL);
}
Assuming pDocTemplate is your template name.
You can then use the returned Document pointer to add information, load files, give commands, etc.
This is basically some sample code for gurly's solution.
(In your CWinApp child InitInstance() you have someththing like:
pDocTemplate = new CMultiDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CMAMReportsD
RUNTIME_CLASS(CChildFrame)
RUNTIME_CLASS(CMAMReportsV
AddDocTemplate(pDocTemplat
You can add a function to your tree control, like:
CMyDocument *CMyTreeControl::MakeDocum
{
CMyDocument *WorkWinApp = (CMyWinApp *)AfxGetApp();
return (CMyDocument *)WorkWinApp->pDocTemplate
}
Assuming pDocTemplate is your template name.
You can then use the returned Document pointer to add information, load files, give commands, etc.
This is basically some sample code for gurly's solution.
ASKER
Hi Crius,
I have some questions about your answer:
What is CMyDocument? Is it teh document that attached to the tree view?
How do I use this code?
I have some questions about your answer:
What is CMyDocument? Is it teh document that attached to the tree view?
How do I use this code?
CMyDocument is supposed to be the document that is attached to your Rich Edit View.
If you don't have any you may want to add such a class.
If not - you can use the document attached to your tree view.
If neither of these options suites you, you can create the view without using a doc template. just call CreateView on your frame window (child frame / main frame) with an appropriate CCreateContext.
If you don't have any you may want to add such a class.
If not - you can use the document attached to your tree view.
If neither of these options suites you, you can create the view without using a doc template. just call CreateView on your frame window (child frame / main frame) with an appropriate CCreateContext.
ASKER
I'm sorry,
But I do not understand what you're saying.
First of all I tried to write the code you attached and it has problem in the compilation.
It does not allow the CMyDocument *WorkWinApp = (CMyWinApp *)AfxGetApp().
Second, what did you mean with the CCreateContext?
I need to see an example because I don't have any clue.
Thanks
But I do not understand what you're saying.
First of all I tried to write the code you attached and it has problem in the compilation.
It does not allow the CMyDocument *WorkWinApp = (CMyWinApp *)AfxGetApp().
Second, what did you mean with the CCreateContext?
I need to see an example because I don't have any clue.
Thanks
ASKER
I'm sorry,
But I do not understand what you're saying.
First of all I tried to write the code you attached and it has problem in the compilation.
It does not allow the CMyDocument *WorkWinApp = (CMyWinApp *)AfxGetApp().
Second, what did you mean with the CCreateContext?
I need to see an example because I don't have any clue.
Thanks
But I do not understand what you're saying.
First of all I tried to write the code you attached and it has problem in the compilation.
It does not allow the CMyDocument *WorkWinApp = (CMyWinApp *)AfxGetApp().
Second, what did you mean with the CCreateContext?
I need to see an example because I don't have any clue.
Thanks
In order to help you, I need to know if you will need a specific document attached to your rich edit view.
If you do - should it be a different class, or a different instance of your current document (the one attached to the tree view).
If you don't need a specific document, that means you can use the same instance the rich edit view is attached to.
Is that correct ?
If you do - should it be a different class, or a different instance of your current document (the one attached to the tree view).
If you don't need a specific document, that means you can use the same instance the rich edit view is attached to.
Is that correct ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Crius: The example you gave still doesn't work. I get this error:
'pDocTemplate' : is not a member of 'CVideoPlusDebuggerApp' -
where 'CVideoPlusDebuggerApp' is the name my application.
Qurly: The project that I'm writing is has a tree view which is a dockable window. The treeview doesn't have any document because it is based on a code I took from codeguru for creating dockable windows in an MDI application.
The Rich Edit View is has the document, and maybe this causes me all the problems. Isn't it?
In the edit view I would like to open different files, so I think I should have a different document.
Crius: The example you gave still doesn't work. I get this error:
'pDocTemplate' : is not a member of 'CVideoPlusDebuggerApp' -
where 'CVideoPlusDebuggerApp' is the name my application.
Qurly: The project that I'm writing is has a tree view which is a dockable window. The treeview doesn't have any document because it is based on a code I took from codeguru for creating dockable windows in an MDI application.
The Rich Edit View is has the document, and maybe this causes me all the problems. Isn't it?
In the edit view I would like to open different files, so I think I should have a different document.
ASKER
Hi Crius,
I'm returning back my words from he last comment, this cod eis fine and I just made some little modifications and now it looks like this:
CRichEditDoc *CProjectView::MakeDocumen t()
{
CMyApp *WorkWinApp = (CMyApp *)AfxGetApp();
POSITION pos = WorkWinApp->GetFirstDocTem platePosit ion();
CDocTemplate *pDocTemplate =
WorkWinApp->GetNextDocTemp late(pos);
return (CRichEditDoc *)pDocTemplate->OpenDocume ntFile(NUL L);
}
Now I just have to check if everything is fine and if it does I will take this comment.
I'm returning back my words from he last comment, this cod eis fine and I just made some little modifications and now it looks like this:
CRichEditDoc *CProjectView::MakeDocumen
{
CMyApp *WorkWinApp = (CMyApp *)AfxGetApp();
POSITION pos = WorkWinApp->GetFirstDocTem
CDocTemplate *pDocTemplate =
WorkWinApp->GetNextDocTemp
return (CRichEditDoc *)pDocTemplate->OpenDocume
}
Now I just have to check if everything is fine and if it does I will take this comment.
ASKER
Thanks,
This is what I looked for.
Alon
This is what I looked for.
Alon
ASKER
Thanks,
This is what I looked for.
This is what I looked for.
CFile cFile;
CString cText = "Hi, This is a test";
cFile.Open "C:\\Test.txt",CFile::mode
cFile.Write (cText,cText.GetLength());
cFile.Close;