⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doclistdlg.cpp

📁 < MFC经典问答>>是微软类库经常遇到的问题
💻 CPP
字号:
// DocListDlg.cpp : implementation file
//

#include "stdafx.h"
#include "iteratedocs.h"
#include "DocListDlg.h"

#include "EkDocList.h"		// For CEkDocList enumerator class

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDocListDlg dialog


CDocListDlg::CDocListDlg( int nTechnique, CWnd* pParent /*=NULL*/ )
	: CDialog(CDocListDlg::IDD, pParent)
{
	m_nTechnique = nTechnique;
	//{{AFX_DATA_INIT(CDocListDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDocListDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDocListDlg)
	DDX_Control(pDX, IDC_DOCLIST, m_DocList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDocListDlg, CDialog)
	//{{AFX_MSG_MAP(CDocListDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDocListDlg message handlers

BOOL CDocListDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	switch( m_nTechnique )
	{
	default:
		ASSERT( FALSE );	// Should never happen !
		break;

	case 1:
		InitFirstTechnique();
		break;

	case 2:
		InitSecondTechnique();
		break;
	}
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDocListDlg::InitFirstTechnique()
{
	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 );

			// 5 - Add the document pathname or title to our list
			CString strDocName = pDoc->GetPathName();
			if( strDocName.IsEmpty() )
				strDocName = pDoc->GetTitle();

			m_DocList.AddString( strDocName );
		}
	}

	// 6 - Change our title to show the technique used
	CString strDlgTitle;
	GetWindowText( strDlgTitle );
	strDlgTitle += " -- 1st technique";
	SetWindowText( strDlgTitle );
}

void CDocListDlg::InitSecondTechnique()
{
	// 1 - Construct CEkDocList enumerator object
	CEkDocList DocList;

	// 2 - For each document object...
	CDocument* pDoc;
	while( pDoc = DocList.GetNextDoc() )
	{
		// 3 - Add the document pathname or title to our list
		CString strDocName = pDoc->GetPathName();
		if( strDocName.IsEmpty() )
			strDocName = pDoc->GetTitle();

		m_DocList.AddString( strDocName );
	}

	// 4 - Change our title to show the technique used
	CString strDlgTitle;
	GetWindowText( strDlgTitle );
	strDlgTitle += " -- 2nd technique";
	SetWindowText( strDlgTitle );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -