Thread: Doc View - Traversing for all open documents

  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, 01:03 AM
  2. Big help in Astar search code...
    By alvifarooq in forum C++ Programming
    Replies: 6
    Last Post: 09-24-2004, 11:38 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09: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, 05:38 PM