[MFC] Cum enumar documentele intr-o aplicatie MDI?

Despre MFC, ATL si alte biblioteci C++ de la Microsoft (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[MFC] Cum enumar documentele intr-o aplicatie MDI?

Post by Ovidiu Cucu » 01 May 2011, 11:22

Intrebare
Cum enumar toate documentele deschise intr-o aplicatie MDI?

Raspuns
Mai intai enumar template-urile de documente din aplicatie folosind CWinApp::GetFirstDocTemplatePosition si CWinApp::GetNextDocTemplate.
Pentru fiecare template gasit, enumar documentele cu ajutorul functiilor CDocTemplate::GetFirstDocPosition si CDocTemplate::GetNextDoc.

Exemplu

Code: Select all

void CFoo::OnEnumAllDocuments() 
{
   CWinApp* pApp = AfxGetApp();
   ASSERT(NULL != pApp); // no valid CWinApp pointer.

   // loop through application's document templates
   POSITION posDocTemplate = pApp->GetFirstDocTemplatePosition();
   while(NULL != posDocTemplate)
   {
      CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate(posDocTemplate);

      // get each document open in given document template
      POSITION posDoc = pDocTemplate->GetFirstDocPosition();
      while(NULL != posDoc)
      {
         CDocument* pDoc = pDocTemplate->GetNextDoc(posDoc);
         // enjoy of found document (pDoc)...
      }
   }
}
Vezi si << Back to MFC index



Post Reply