📄 cpaintdcdemoview.cpp
字号:
// CPaintDCDemoView.cpp : implementation of the CCPaintDCDemoView class
//
#include "stdafx.h"
#include "CPaintDCDemo.h"
#include "CPaintDCDemoDoc.h"
#include "CPaintDCDemoView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCPaintDCDemoView
IMPLEMENT_DYNCREATE(CCPaintDCDemoView, CView)
BEGIN_MESSAGE_MAP(CCPaintDCDemoView, CView)
//{{AFX_MSG_MAP(CCPaintDCDemoView)
ON_WM_PAINT()
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()
/////////////////////////////////////////////////////////////////////////////
// CCPaintDCDemoView construction/destruction
CCPaintDCDemoView::CCPaintDCDemoView()
{
// TODO: add construction code here
}
CCPaintDCDemoView::~CCPaintDCDemoView()
{
}
BOOL CCPaintDCDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCPaintDCDemoView drawing
void CCPaintDCDemoView::OnDraw(CDC* pDC)
{
CCPaintDCDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCPaintDCDemoView printing
BOOL CCPaintDCDemoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCPaintDCDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCPaintDCDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCPaintDCDemoView diagnostics
#ifdef _DEBUG
void CCPaintDCDemoView::AssertValid() const
{
CView::AssertValid();
}
void CCPaintDCDemoView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCPaintDCDemoDoc* CCPaintDCDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCPaintDCDemoDoc)));
return (CCPaintDCDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCPaintDCDemoView message handlers
void CCPaintDCDemoView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;//创建矩形区域,存储客户窗口区域
GetClientRect(&rect);//得到客户区的范围放到rect中
dc.Rectangle(0,0,(rect.left+rect.right)/2,(rect.top+rect.bottom)/2);//在客户窗口的左上角绘制矩形,大小占据1/4窗口
dc.Ellipse((rect.left+rect.right)/2,(rect.top+rect.bottom)/2,rect.right,rect.bottom);//在客户窗口的右下角绘制椭圆,大小占据1/4窗口
// Do not call CView::OnPaint() for painting messages
}
void CCPaintDCDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);//创建CClientDC类对象
CRect rc;//创建矩形区域,存储客户窗口区域
GetClientRect(&rc);//得到客户区的范围放到rc中
dc.MoveTo(0,0);//将画笔的当前位置移到客户区的左上角
dc.LineTo(rc.right,rc.bottom);//从左上角画直线到右下角
dc.MoveTo(rc.right,0);//将画笔的当前位置移到客户区的上上角
dc.LineTo(0,rc.bottom);//从右上角画直线到左下角
CView::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -