void CMyApp::DoSomethingToAllDocs() 

    { 

    CObList pDocList; 

    POSITION pos = GetFirstDocTemplatePosition(); 

    while(pos) 

        { 

        CDocTemplate* pTemplate = GetNextDocTemplate(pos); 

        POSITION pos2 = pTemplate->GetFirstDocPosition(); 

        while(pos2) 

            { 

            CDocument* pDocument; 

            if(pDocument = pTemplate->GetNextDoc(pos2)) 

            pDocList.AddHead(pDocument); 

        } 

    } 

    if(!pDocList.IsEmpty()) 

        { 

        pos = pDocList.GetHeadPosition(); 

        while(pos) 

            { 

            // Call some CDocument function for each

            //     document 

            ( (CDocument*)pDocList.GetNext(pos) )->UpdateAllViews(NULL); 

        } 

    }