📄 s10_4view.cpp
字号:
// s10_4View.cpp : implementation of the CS10_4View class
//
#include "stdafx.h"
#include "s10_4.h"
#include "s10_4Doc.h"
#include "s10_4View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CS10_4View
IMPLEMENT_DYNCREATE(CS10_4View, CView)
BEGIN_MESSAGE_MAP(CS10_4View, CView)
//{{AFX_MSG_MAP(CS10_4View)
ON_COMMAND(ID_MENUITEM_BRUSH1, OnMenuitemBrush1)
ON_COMMAND(ID_MENUITEM_BRUSH2, OnMenuitemBrush2)
ON_COMMAND(ID_MENUITEM_BRUSH3, OnMenuitemBrush3)
ON_COMMAND(ID_MENUITEM_PEN1, OnMenuitemPen1)
ON_COMMAND(ID_MENUITEM_PEN2, OnMenuitemPen2)
ON_COMMAND(ID_MENUITEM_PEN3, OnMenuitemPen3)
ON_COMMAND(ID_MENUITEM_FONT1, OnMenuitemFont1)
ON_COMMAND(ID_MENUITEM_FONT2, OnMenuitemFont2)
ON_COMMAND(ID_MENUITEM_FONT3, OnMenuitemFont3)
ON_WM_LBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CS10_4View construction/destruction
CS10_4View::CS10_4View()
{
// TODO: add construction code here
}
CS10_4View::~CS10_4View()
{
}
BOOL CS10_4View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CS10_4View drawing
void CS10_4View::OnDraw(CDC* pDC)
{
CS10_4Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int xCoordinate, yCoordinate; // 当前鼠标单击位置
xCoordinate = pDoc->m_oMousePoint.x;
yCoordinate = pDoc->m_oMousePoint.y;
CPen oPen;
CPen *pOldPen;
CBrush oBrush;
CBrush *pOldBrush;
CFont oFont;
CFont *pOldFont;
switch(m_GdiType)
{
case PEN:
{
oPen.CreatePen(PS_SOLID, pDoc->m_iPenWidth, RGB(0, 0, 255));
pOldPen = pDC->SelectObject(&oPen);
pDC->MoveTo(xCoordinate, yCoordinate);
pDC->LineTo(xCoordinate + 300, yCoordinate);
pDC->SelectObject(pOldPen);
break;
}
case BRUSH:
{
oBrush.CreateHatchBrush(pDoc->m_iBrushStyle, RGB(0, 0, 255));
pOldBrush = pDC->SelectObject(&oBrush);
pDC->Ellipse(xCoordinate - 200, yCoordinate - 50, xCoordinate + 200, yCoordinate + 50);
pDC->SelectObject(pOldBrush);
break;
}
case FONT:
{
oFont.CreateFontIndirect(&pDoc->m_sLogFont);
pOldFont = pDC->SelectObject(&oFont);
pDC->TextOut(xCoordinate, yCoordinate, "字体演示!");
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CS10_4View printing
BOOL CS10_4View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CS10_4View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CS10_4View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CS10_4View diagnostics
#ifdef _DEBUG
void CS10_4View::AssertValid() const
{
CView::AssertValid();
}
void CS10_4View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CS10_4Doc* CS10_4View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CS10_4Doc)));
return (CS10_4Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CS10_4View message handlers
void CS10_4View::OnMenuitemBrush1()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_iBrushStyle = HS_HORIZONTAL; // 水平阴影线
m_GdiType = BRUSH;
}
void CS10_4View::OnMenuitemBrush2()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_iBrushStyle = HS_VERTICAL; // 垂直阴影线
m_GdiType = BRUSH;
}
void CS10_4View::OnMenuitemBrush3()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_iBrushStyle = HS_DIAGCROSS; // 交叉阴影线
m_GdiType = BRUSH;
}
void CS10_4View::OnMenuitemPen1()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_iPenWidth = 80; // 粗画笔
m_GdiType = PEN;
}
void CS10_4View::OnMenuitemPen2()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_iPenWidth = 40; // 中画笔
m_GdiType = PEN;
}
void CS10_4View::OnMenuitemPen3()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_iPenWidth = 10; // 细画笔
m_GdiType = PEN;
}
void CS10_4View::OnMenuitemFont1()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_sLogFont.lfHeight = 80; // 大字体
m_GdiType = FONT;
}
void CS10_4View::OnMenuitemFont2()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_sLogFont.lfHeight = 30; // 中字体
m_GdiType = FONT;
}
void CS10_4View::OnMenuitemFont3()
{
// TODO: Add your command handler code here
CS10_4Doc *pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->m_sLogFont.lfHeight = 15; // 小字体
m_GdiType = FONT;
}
void CS10_4View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CS10_4Doc *pDoc = GetDocument(); // 取得文档类的指针
ASSERT_VALID(pDoc);
pDoc->m_oMousePoint = point; // 保存当前鼠标的单击位置
Invalidate(); // 使当前客户区无效,重绘客户区
CView::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -