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

📄 rotateview.cpp

📁 这个是我们学校用的VC++教案
💻 CPP
字号:
// RotateView.cpp : implementation of the CRotateView class
//

#include "stdafx.h"
#include "Rotate.h"

#include "RotateDoc.h"
#include "RotateView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define  WM_MYMESSAGE  WM_USER+1  // 用户自定义消息
/////////////////////////////////////////////////////////////////////////////
// CRotateView

IMPLEMENT_DYNCREATE(CRotateView, CView)

BEGIN_MESSAGE_MAP(CRotateView, CView)
	//{{AFX_MSG_MAP(CRotateView)
	ON_WM_CREATE()
	ON_WM_DESTROY()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	ON_MESSAGE(WM_MYMESSAGE,OnMyMyessage)  // 自定义消息映射宏
	// 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()

/////////////////////////////////////////////////////////////////////////////
// CRotateView construction/destruction

CRotateView::CRotateView()
{
	m_dEscapement=0;  // 初始化文本显示角度
}

CRotateView::~CRotateView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CRotateView drawing

void CRotateView::OnDraw(CDC* pDC)
{
	CRotateDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CRotateView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CRotateView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CRotateView message handlers

int CRotateView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	// TODO: Add your specialized creation code here
	SetTimer(1,200,NULL);  // 启动定时器
	return 0;
}

void CRotateView::OnDestroy() 
{
	CView::OnDestroy();
	
	// TODO: Add your message handler code here
	KillTimer(1);  // 销毁定时器
	
}

void CRotateView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	SendMessage(WM_MYMESSAGE);  // 发送自定义消息WM_MYMESSAGE
	CView::OnTimer(nIDEvent);
}
LRESULT CRotateView::OnMyMyessage(WPARAM wParam, LPARAM lParam)
{
	CClientDC dc(this);
	m_dEscapement=(m_dEscapement+100) % 3600;
	CFont  fontRotate;  // 准备创建旋转字体
	fontRotate.CreateFont(30,0,m_dEscapement,0,0,0,0,0,0,0,0,0,0,0);  
	CFont* pOldFont=dc.SelectObject(&fontRotate);  // 设置新的字体
	CRect rClient;
	GetClientRect(rClient); // 得到客户窗口大小
	dc.FillSolidRect(&rClient,RGB(255,255,255));  // 为了得到动画效果,将客户区置为白色
	dc.TextOut(rClient.right/2,rClient.bottom/2,"不登高山,不知天之高也");
	dc.SelectObject(pOldFont);  // 恢复原来的字体
	return 0;
}

⌨️ 快捷键说明

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