|
-
April 8th, 2003, 07:31 AM
#1
accessing the 2n template on the list
what does this statement mean
iterate through all the DocTemplates in the App, use CWinApp::GetFirstDocTemplatePosition() and CWinApp::GetNextDocTemplate().
i want to access the doctemplate2 which i have registeredin the app class and display it in a window.
how should i iterate and get the pointer to this doctemplate ?
regards
-
April 8th, 2003, 07:37 AM
#2
-
April 8th, 2003, 07:51 AM
#3
Re: accessing the 2n template on the list
Originally posted by mohamed123
what does this statement mean
iterate through all the DocTemplates in the App, use CWinApp::GetFirstDocTemplatePosition() and CWinApp::GetNextDocTemplate().
It means to write code like this:
Code:
void CMyApp::DoSomethingToAllTemplates()
{
POSITION pos = GetFirstDocTemplatePosition();
while(pos)
{
CDocTemplate* pTemplate = GetNextDocTemplate(pos);
// Do something with pTemplate here...
}
}
This is the 'official' way. To get the second template, you could use a counter or just write something like this:
Code:
POSITION pos = GetFirstDocTemplatePosition();
if(pos)
{
GetNextDocTemplate(pos);
if(pos)
{
CDocTemplate* pTemplate = GetNextDocTemplate(pos);
// pTemplate now points to the second template
}
}
However, I always found it easier to store the pointers to multiple templates in member variables of the app and access them directly.
-
April 8th, 2003, 08:26 AM
#4
hi
thanx
but i am getting a dilog to select between two views.
and the application closes after this but when i check the Task-Manager , the exe file is running
any idea
regards
-
April 8th, 2003, 08:31 AM
#5
Can you explain better what is happening and what you are trying to do (code)?
-
April 8th, 2003, 08:37 AM
#6
this is what is in the app class
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_SYRELATYPE,
RUNTIME_CLASS(CSyRelAnDoc),
RUNTIME_CLASS(CChildFrame), // Benutzerspezifischer MDI-Child-Rahmen
RUNTIME_CLASS(CSyRelAnView));
AddDocTemplate(pDocTemplate);
CMultiDocTemplate* pDocTemplate1;
pDocTemplate1 = new CMultiDocTemplate(
IDR_SYRELATYPE,
RUNTIME_CLASS(CStateEditorDoc),
RUNTIME_CLASS(CChildFrame), // Benutzerspezifischer MDI-Child-Rahmen
RUNTIME_CLASS(CStateEditor));
AddDocTemplate(pDocTemplate1);
in the function void CSyRelAnView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
..........
.................
CDocManager *pDocMan = AfxGetApp()->m_pDocManager;
// get pointer
CDocTemplate *pTemplate = NULL;
POSITION pos = pDocMan->GetFirstDocTemplatePosition();
if(pDocMan->GetNextDocTemplate(pos))
{
pTemplate=pDocMan->GetNextDocTemplate(pos);
}
CStateEditorDoc* pDoc = (CStateEditorDoc*)pTemplate->OpenDocumentFile(NULL, TRUE);
..................
etc.
-
April 8th, 2003, 08:53 AM
#7
Why are you using CDocManager? This is an undocumented class, private to MFC. Just call AfxGetApp()->GetFirstTemplatePosition() instead.
Another point: You are calling GetNextDocTemplate(pos) without checking if (pos != NULL). This is unsafe, but shouldn't impose any practical problem in your case, as you know that you have two templates.
You still did not explain what exactly happens when the OpenDocumentFile(NULL, TRUE) call is made. This should normally create a CStateEditorDoc and display it in a new CStateEditor view window. What is happening instead?
-
April 8th, 2003, 08:57 AM
#8
yes
but what i get now is that
a dialog called New is popping up and asking to select between 2 names and then the application closes
i dont know why
thanx any way for th help till now
-
April 8th, 2003, 09:02 AM
#9
This seems nearly impossible... This happens if you call your app's OnNewDocument somewhere, but not when you call OpenDocumentFile(NULL) on a document template. Could you post the entire OnLButtonDblClk() implementation (please use code tags this time)?
-
April 8th, 2003, 09:23 AM
#10
i have not added OnNewDocument anywhere
but this small dialog pops up only when i add the new template in the app class.
is it problem of now linking the document and view properly or ?
void CSyRelAnView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CDocTemplate *pTemplate = NULL;
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
if(AfxGetApp()->GetNextDocTemplate(pos))
{
pTemplate=AfxGetApp()->GetNextDocTemplate(pos);
}
CStateEditorDoc* pDoc = (CStateEditorDoc*)pTemplate->OpenDocumentFile(NULL, TRUE);
}
-
April 8th, 2003, 09:43 AM
#11
When does the dialog pop up? When you start the application or when you double click in the view?
-
April 8th, 2003, 09:45 AM
#12
when i start the application and then the application closes but the exe file is running in the background
-
April 8th, 2003, 09:57 AM
#13
Well, you didn't say that... You have to override the OnFileNew() handler for your application and do exactly what you are doing now in your OnLButtonDblClk() (assuming you want a doc/view of the second type at startup). The OnFileNew() default implementation of CWinApp shows this dialog as soon as there is more then one document template.
BTW, you should rewrite your code like this:
Code:
void CSyRelAnView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CDocTemplate *pTemplate = NULL;
POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
if(pos)
{
AfxGetApp()->GetNextDocTemplate(pos);
if(pos)
{
pTemplate=AfxGetApp()->GetNextDocTemplate(pos);
CStateEditorDoc* pDoc = (CStateEditorDoc*)pTemplate->OpenDocumentFile(NULL, TRUE);
}
}
}
-
April 8th, 2003, 10:14 AM
#14
hi
thanx
i want the first doctemplate -view at the start up and i want the 2nd doctemplate-view on double click
-
April 8th, 2003, 10:21 AM
#15
OK, so just call OpenDocumentFile(NULL) on the first template in your App's OnNewDocument().
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|