Doc View - Traversing for all open documents

This is a discussion on Doc View - Traversing for all open documents within the Windows Programming forums, part of the Platform Specific Boards category; I'm writing a CRichEditDoc/View app. I'm not too familiar with all of its intricacies so perhaps you can assist me... ...

  1. #1
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856

    Doc View - Traversing for all open documents

    I'm writing a CRichEditDoc/View app. I'm not too familiar with all of its intricacies so perhaps you can assist me...
    I am unaware of how to go about traversing all open documents. I am doing this from my CMainFrame class and know that I can use CFrameWnd::GetActiveDocument() to retrieve a pointer to the active document. I also know that in CDocument I can call GetNextView() to traverse views (although I am unsure why you can do this as I thought there was a one-to-one relationship between docs and views, but eh). The thing I can't figure out is how to retrieve pointers to each open CDocument in the app..

    As always, all assistance is greatly appreciated. Thanks.

  2. #2
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    I figured out how to do this... In case anyone else has had this problem this is how I did it:
    Code:
      CMasmEditDoc *openedDoc = NULL;
    
      // find the view with our target filename
      POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition();
      while (pos != NULL && openedDoc == NULL) {
        CDocTemplate *doc = AfxGetApp()->GetNextDocTemplate(pos);
    
        POSITION docpos = doc->GetFirstDocPosition();
        while (docpos != NULL) {
          CDocument *richDoc = doc->GetNextDoc(docpos);
          if (richDoc != NULL)
            if (_tcsicmp(richDoc->GetPathName(), src) == 0) {
              openedDoc = (CMasmEditDoc*)richDoc;
              break;
            }
        }
      }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to View Open Connections
    By maththeorylvr in forum Windows Programming
    Replies: 8
    Last Post: 05-01-2005, 02:03 AM
  2. Big help in Astar search code...
    By alvifarooq in forum C++ Programming
    Replies: 6
    Last Post: 09-24-2004, 12:38 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  4. How to open two view i MFC
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 02-05-2002, 04:13 PM
  5. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 06:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21