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

📄 createoractivatedoc.cpp

📁 Visual_C++[1].NET_Bible1 Visual_C++宝典书中的全部源码
💻 CPP
字号:
// CreateOrActivateDoc.cpp : implementation of the CCreateOrActivateDoc class
//

#include "stdafx.h"
#include "CreateOrActivate.h"

#include "CreateOrActivateDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CCreateOrActivateDoc

IMPLEMENT_DYNCREATE(CCreateOrActivateDoc, CDocument)

BEGIN_MESSAGE_MAP(CCreateOrActivateDoc, CDocument)
  ON_COMMAND(ID_MYVIEWS_VIEW1, OnMyviewsView1)
  ON_COMMAND(ID_MYVIEWS_VIEW2, OnMyviewsView2)
END_MESSAGE_MAP()


// CCreateOrActivateDoc construction/destruction

CCreateOrActivateDoc::CCreateOrActivateDoc()
{
 CWinApp* pApp = AfxGetApp();
 ASSERT(pApp);

 if (pApp) 
 {   
  m_pFormView1Template = 
   new CMultiDocTemplate(IDR_CreateOrActivatTYPE,
    RUNTIME_CLASS(CCreateOrActivateDoc),
    RUNTIME_CLASS(CChildFrame),
    RUNTIME_CLASS(CFormView1));
  pApp->AddDocTemplate(m_pFormView1Template);

  m_pFormView2Template = 
   new CMultiDocTemplate(IDR_CreateOrActivatTYPE,
    RUNTIME_CLASS(CCreateOrActivateDoc),
    RUNTIME_CLASS(CChildFrame),
    RUNTIME_CLASS(CFormView2));
  pApp->AddDocTemplate(m_pFormView2Template);
 }
}

CCreateOrActivateDoc::~CCreateOrActivateDoc()
{
}

BOOL CCreateOrActivateDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}




// CCreateOrActivateDoc serialization

void CCreateOrActivateDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}


// CCreateOrActivateDoc diagnostics

#ifdef _DEBUG
void CCreateOrActivateDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CCreateOrActivateDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG


// CCreateOrActivateDoc commands

void CCreateOrActivateDoc::OnMyviewsView1()
{
  CreateOrActivateFrame(m_pFormView1Template, RUNTIME_CLASS(CFormView1));
}

void CCreateOrActivateDoc::OnMyviewsView2()
{
  CreateOrActivateFrame(m_pFormView2Template, RUNTIME_CLASS(CFormView2));
}

void CCreateOrActivateDoc::CreateOrActivateFrame(CDocTemplate* pTemplate, CRuntimeClass* pViewClass)
{                
  // Search through document's attatched views
  CView* pView;
  POSITION pos = GetFirstViewPosition();
  while (pos != NULL)
  {
   pView = GetNextView(pos);
   // If the kind found matches kind passed as parameter, activate it
   if (pView->IsKindOf(pViewClass))
   {
    pView->GetParentFrame()->ActivateFrame(SW_RESTORE);
    return;
   }                                                                 
  }		       
  // Did not find the correct active, so create and initialize one
  CFrameWnd* pFrame = pTemplate->CreateNewFrame(this, NULL);
  ASSERT(pFrame);
  pTemplate->InitialUpdateFrame(pFrame, this);
}

⌨️ 快捷键说明

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