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

📄 ex07_2doc.cpp

📁 内容包括从VC++的基本范例到项目开发的许多典型的例子。是VC++初学者不可多得的好资料
💻 CPP
字号:
// Ex07_2Doc.cpp : implementation of the CEx07_2Doc class
//

#include "stdafx.h"
#include "Ex07_2.h"

#include "Ex07_2Doc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEx07_2Doc

IMPLEMENT_DYNCREATE(CEx07_2Doc, CDocument)

BEGIN_MESSAGE_MAP(CEx07_2Doc, CDocument)
	//{{AFX_MSG_MAP(CEx07_2Doc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEx07_2Doc construction/destruction

CEx07_2Doc::CEx07_2Doc()
{
	// TODO: add one-time construction code here

}

CEx07_2Doc::~CEx07_2Doc()
{
     ReInit();
}

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

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	ReInit();
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CEx07_2Doc serialization

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

/////////////////////////////////////////////////////////////////////////////
// CEx07_2Doc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CEx07_2Doc commands
void CEx07_2Doc::ReInit()
{
	CLine *pLine;
	POSITION pos=m_LineList.GetHeadPosition();
	for(;pos!=NULL;m_LineList.GetNext(pos))
	{
		pLine=(CLine*)m_LineList.GetAt(pos);
		delete pLine;
	}
	m_LineList.RemoveAll();
	m_strList.RemoveAll();

}

  void CEx07_2Doc::DrawLine(CDC*pDC)
  {
	  //取得需要重绘的区域
	 CRect rectClip;
	  pDC->GetClipBox(&rectClip);
	  CLine *pLine;
	  POSITION pos=m_LineList.GetHeadPosition();

	  for(;pos!=NULL;m_LineList.GetNext(pos))
	  {
		  pLine=(CLine*)m_LineList.GetAt(pos);
		  if(rectClip.PtInRect(pLine->m_StartPt)||rectClip.PtInRect(pLine->m_EndPt))
		  {
			  pLine->Draw(pDC);
		  }
	  }
  }
 void CEx07_2Doc::DrawText(CDC*pDC)
  {  //取得需要重绘的区域
	 CRect rectClip,rect;
	  pDC->GetClipBox(&rectClip);
      CSize size;
	  TEXTMETRIC tm;
	  pDC->GetTextMetrics(&tm);
	  int nLineHeight=tm.tmHeight+tm.tmExternalLeading;
	  CString str;
	  int line=0;
	  POSITION pos=m_strList.GetHeadPosition();
	  for(;pos!=NULL;m_strList.GetNext(pos))
	  {
		  str=m_strList.GetAt(pos);
		  size=pDC->GetTextExtent(str);
		  rect.SetRect(0,line*nLineHeight,size.cx,line*nLineHeight+size.cy);
		  if(!(rect&rectClip).IsRectEmpty())pDC->TextOut(0,line*nLineHeight,str);
		  line++;
	  }
	  str=m_strLastLine;
      size=pDC->GetTextExtent(str);
	  rect.SetRect(0,line*nLineHeight,size.cx,line*nLineHeight+size.cy);
	  if(!(rect&rectClip).IsRectEmpty())
		  pDC->TextOut(0,line*nLineHeight,str);
     
  }

⌨️ 快捷键说明

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