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

📄 ex5_1view.cpp

📁 C++程序设计源代码例
💻 CPP
字号:
// Ex5_1View.cpp : implementation of the CEx5_1View class
//

#include "stdafx.h"
#include "Ex5_1.h"

#include "Ex5_1Doc.h"
#include "Ex5_1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEx5_1View

IMPLEMENT_DYNCREATE(CEx5_1View, CView)

BEGIN_MESSAGE_MAP(CEx5_1View, CView)
	//{{AFX_MSG_MAP(CEx5_1View)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEx5_1View construction/destruction

CEx5_1View::CEx5_1View()
{
	// TODO: add construction code here
	nColorSign=0;
	nFirst=0;
	OutStr="风声雨声读书声声声入耳";
	nFontSign=0;
	OutStrLen=OutStr.GetLength();
	nFontHeight=8;

}

CEx5_1View::~CEx5_1View()
{
}

BOOL CEx5_1View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEx5_1View drawing

void CEx5_1View::OnDraw(CDC* pDC)
{
	CEx5_1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
   pDC->SetTextColor (nColorSign%255);//根据nColorSign线性设置颜色    	
   CString chfont;   // 表示字体	
   switch(nFontSign%5)//根据nFontSign的值选择字体	
   {
   case 0:chfont="楷体_GB2312";
    	break;	 
   case 1:chfont="宋体";
    	break;	 
   case 2:chfont="隶书";
	    break;	 
   case 3:chfont="黑体";
	    break;	 
   case 4:chfont="幼圆";
	    break;	
   }	
   CFont NewFont; //创建新字体	
   NewFont.CreateFont (nFontHeight,10,0,0,0,false,false,false,GB2312_CHARSET,		   
		    			OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,		   
		    			DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE,chfont);    
   pDC->SelectObject (NewFont);	
   //输出从nFirst开始的文本串	
   pDC->TextOut(100,150, OutStr.Mid(nFirst));

}

/////////////////////////////////////////////////////////////////////////////
// CEx5_1View printing

BOOL CEx5_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEx5_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEx5_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEx5_1View diagnostics

#ifdef _DEBUG
void CEx5_1View::AssertValid() const
{
	CView::AssertValid();
}

void CEx5_1View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEx5_1Doc* CEx5_1View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx5_1Doc)));
	return (CEx5_1Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEx5_1View message handlers

void CEx5_1View::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
    SetTimer( 1, 350, NULL);
	
	CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

void CEx5_1View::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
   	nFirst=nFirst+2; //设置文本串开始位置,向前走一个汉字	
	if(nFirst>=OutStrLen)//文本串开始位置归0,并修改字体和颜色	
	{ 
		nFirst=0;    	  
		nColorSign+=20;	  
		nFontSign++;	  
		if(nFontHeight==40)		 
			nFontHeight=8;	  
		else		  
			nFontHeight=nFontHeight+8;	  
	}	
	this->Invalidate (true);
	
	CView::OnTimer(nIDEvent);
}

⌨️ 快捷键说明

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