CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Nov 2000
    Location
    Germany
    Posts
    645

    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

  2. #2
    Join Date
    May 2000
    Location
    Toronto, ON, Canada
    Posts
    3,573
    http://msdn.microsoft.com/archive/de...n_mfcfaq50.asp
    Look for How do I get a list of open documents?
    Regards,

    Emanuel Vaduva

  3. #3
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    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.

  4. #4
    Join Date
    Nov 2000
    Location
    Germany
    Posts
    645
    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

  5. #5
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Can you explain better what is happening and what you are trying to do (code)?

  6. #6
    Join Date
    Nov 2000
    Location
    Germany
    Posts
    645
    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.

  7. #7
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    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?

  8. #8
    Join Date
    Nov 2000
    Location
    Germany
    Posts
    645
    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

  9. #9
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    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)?

  10. #10
    Join Date
    Nov 2000
    Location
    Germany
    Posts
    645
    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);

    }

  11. #11
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    When does the dialog pop up? When you start the application or when you double click in the view?

  12. #12
    Join Date
    Nov 2000
    Location
    Germany
    Posts
    645
    when i start the application and then the application closes but the exe file is running in the background

  13. #13
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    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);
        }
      }
    }

  14. #14
    Join Date
    Nov 2000
    Location
    Germany
    Posts
    645
    hi
    thanx
    i want the first doctemplate -view at the start up and i want the 2nd doctemplate-view on double click

  15. #15
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    OK, so just call OpenDocumentFile(NULL) on the first template in your App's OnNewDocument().

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured