Multidoc templates
Janardan R. Sethi -- sethijr@logic.clarkson.edu
Monday, December 02, 1996
Hi,
Environment: VC++4.0 MFC 4.0 WindowsNT 4.0
My application requires 2 documents of different types with just one
object each created when the application is run. I am using
CMultidoctemplate to create the 2 documents but i am not able to construct
them on initialization of the application. How can i create the two
objects on initialization of the application.
I would also like the two document objects to communicate on occurence of
an event in one of the documents, without calling the member function of
the other document. Is there any way in which i could generate some sort
of window message that could be handled by the other document.
Thanking you in advance,
Sethi J
sethijr@craft.clarkson.edu
Doug Brubacher -- Doug_Brubacher@compuware.com
Thursday, December 05, 1996
[Mini-digest: 3 responses]
Sethi,
Your CMultiDocTemplate instance, which you use in
CYourApp::InitInstance to add your document templates, inherits from
CDocTemplate.
To construct your two documents on application initialization use the
function CDocTemplate::OpenDocumentFile();
Here's a sample InitInstance with only one document template that
demonstrates this:
BOOL CMyApp::InitInstance()
{
// Register the application's document templates. Document
templates
// serve as the connection between documents, frame windows and
views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_MFCLTYPE,
RUNTIME_CLASS(CMyDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CMyView));
AddDocTemplate(pDocTemplate);
pDocTemplate->OpenDocumentFile(NULL); // HERE'S THE LINE TO
CONSTRUCT A DOCUMENT.
// NOTE YOU HAVE TO WAIT TILL THE MAINFRAME HAS BEEN CREATED BEFORE
MKAING THIS CALL.
return TRUE;
}
As for your second question, only the active document is part of the
standard MFC command routing. The best solution is probably to route
it directly your self by trapping it in the MainFrame and then
manually routing it to the documents you desire. Unfortunately that
sounds like exactly what you did not want to do.
CWinApp provides GetFirstDocTemplatePosition and GetNextDocTemplate
which makes it more convenient to walk the document templates and
documents in your application, but it is still a bit of a pain.
Regards,
Doug Brubacher
DouglasB@msn.com
-----From: "Janardan R. Sethi"
Hi,
Environment: VC++4.0 MFC 4.0 WindowsNT 4.0
My application requires 2 documents of different types with just one
object each created when the application is run. I am using
CMultidoctemplate to create the 2 documents but i am not able to construct
them on initialization of the application. How can i create the two
objects on initialization of the application.
I would also like the two document objects to communicate on occurence of
an event in one of the documents, without calling the member function of
the other document. Is there any way in which i could generate some sort
of window message that could be handled by the other document.
Thanking you in advance,
Sethi J
sethijr@craft.clarkson.edu
-----From: "P. Senthil"
Janardan R. Sethi wrote:
>
> Hi,
> Environment: VC++4.0 MFC 4.0 WindowsNT 4.0
>
> My application requires 2 documents of different types with just one
> object each created when the application is run. I am using
> CMultidoctemplate to create the 2 documents but i am not able to construct
> them on initialization of the application. How can i create the two
> objects on initialization of the application.
>
> I would also like the two document objects to communicate on occurence of
> an event in one of the documents, without calling the member function of
> the other document. Is there any way in which i could generate some sort
> of window message that could be handled by the other document.
>
> Thanking you in advance,
> Sethi J
> sethijr@craft.clarkson.edu
1. You can't create two different documents on the same template. Use
different templates for the documents.
2. Documents can't handle messages as they are not derived from CWnd.
You can communicate (through member functions) through the template. You
can iterate through the document list use GetFirstDocPosition and
GetNextDoc which are members of the template.
P. Senthil
mail:senthilp@geocities.com
www :www.geocities.com/SiliconValley/Heights/6504/
| Вернуться в корень Архива
|