对于MDI程序中打开的多个文档,我要得到所有文档的路径,如何实现枚举?

解决方案 »

  1.   

    在你的doc类中,使用 CString sPath = this->GetPathName();可以获得当前活动文档的名称。
      

  2.   

    CWinApp* pApp = AfxGetApp();
    ASSERT_VALID( pApp );// 1 - Iterate through the application's document
    // templates list
    POSITION posTemplate =
       pApp->GetFirstDocTemplatePosition();
    while( posTemplate != NULL )
    {
    // 2 - For each document template object...
    CDocTemplate* pTemplate =
    pApp->GetNextDocTemplate( posTemplate );
    ASSERT_VALID( pTemplate );
    ASSERT_KINDOF( CDocTemplate, pTemplate ); // 3 - Iterate through the template's document list
    POSITION posDocument =
       pTemplate->GetFirstDocPosition();
    while( posDocument != NULL )
    {
    // 4 - For each document object...
    CDocument* pDoc =
    pTemplate->GetNextDoc( posDocument );
    ASSERT_VALID( pDoc );
    ASSERT_KINDOF( CDocument, pDoc );
    CString strDocName = pDoc->GetPathName();//This is the document' path
    if( strDocName.IsEmpty() )
    strDocName = pDoc->GetTitle();
    }
    }