📄 chapter13aview.cpp
字号:
// Chapter13AView.cpp : implementation of the CChapter13AView class
//
#include "stdafx.h"
#include "Chapter13A.h"
#include "Chapter13ADoc.h"
#include "Chapter13AView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChapter13AView
IMPLEMENT_DYNCREATE(CChapter13AView, CView)
BEGIN_MESSAGE_MAP(CChapter13AView, CView)
//{{AFX_MSG_MAP(CChapter13AView)
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()
/////////////////////////////////////////////////////////////////////////////
// CChapter13AView construction/destruction
CChapter13AView::CChapter13AView()
{
// TODO: add construction code here
m_iRed=255;
m_iGreen=0;
m_iBlue= 128;
x=y=0;
}
CChapter13AView::~CChapter13AView()
{
}
BOOL CChapter13AView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CChapter13AView drawing
void CChapter13AView::OnDraw(CDC* pDC)
{
CChapter13ADoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
//设置映射模式
pDC->SetMapMode(MM_ANISOTROPIC);
//客户区的大小
CRect rcClient;
GetClientRect (rcClient);
//创建输出字符串.
CString str (_T (")))))...字体、画刷、画笔综合!"));
//输出透明字体
pDC->SetBkMode (TRANSPARENT);
pDC->SetTextColor (RGB (m_iRed,m_iGreen,m_iBlue));
//字体定义结构
LOGFONT stFont;
//设置字体格式
memset(&stFont, 0, sizeof(LOGFONT));
stFont.lfCharSet=134;
stFont.lfHeight=100;
stFont.lfWidth=0;
strcpy(stFont.lfFaceName,"华文行楷");
stFont.lfClipPrecision=CLIP_LH_ANGLES;
//创建画刷
CBrush brush(HS_DIAGCROSS,RGB (m_iRed,m_iGreen,m_iBlue+30));
CBrush* pOldBrush;
pOldBrush=pDC->SelectObject(&brush);
//每隔15度输出字符串
for (int nAngle=3600; nAngle>0; nAngle-=150)
{
//设定新的旋转角度
stFont.lfEscapement=nAngle;
//创建字体并选进设备上下文
CFont font;
font.CreateFontIndirect(&stFont);
CFont* pOldFont=pDC ->SelectObject(&font);
pDC->TextOut(x,y,str);
//创建画笔
CPen pen(PS_SOLID,1,RGB (m_iRed,m_iGreen,m_iBlue));
CPen* pOldPen;
pOldPen=pDC->SelectObject(&pen);
//路径包
pDC->BeginPath();
pDC->TextOut(0,0,"(((((.....路径测试:)");
pDC->EndPath();
pDC->StrokeAndFillPath();
//原来字体
pDC->SelectObject(pOldFont);
pDC->SelectObject(pOldPen);
//停顿10毫秒
Sleep(100);
}
//更新文本位置,文本位置为随机产生
x=(rand()*rcClient.Width())/RAND_MAX;
y=(rand()*rcClient.Height())/RAND_MAX;
//恢复刷子
pDC->SelectObject(pOldBrush);
}
/////////////////////////////////////////////////////////////////////////////
// CChapter13AView printing
BOOL CChapter13AView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CChapter13AView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CChapter13AView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CChapter13AView diagnostics
#ifdef _DEBUG
void CChapter13AView::AssertValid() const
{
CView::AssertValid();
}
void CChapter13AView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CChapter13ADoc* CChapter13AView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CChapter13ADoc)));
return (CChapter13ADoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChapter13AView message handlers
void CChapter13AView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
SetTimer(0,10,NULL);
}
void CChapter13AView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//改变文本的颜色值
m_iRed=m_iRed<=205?m_iRed+50:(m_iRed==255?0:255);
m_iGreen=m_iGreen<=205?m_iGreen+50:(m_iGreen==255?0:255);
m_iBlue=m_iBlue<=205?m_iBlue+50:(m_iBlue==255?0:255);
//重画文字
Invalidate();
CView::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -