📄 recttestview.cpp
字号:
// RectTestView.cpp : implementation of the CRectTestView class
//
#include "stdafx.h"
#include "RectTest.h"
#include "RectTestDoc.h"
#include "RectTestView.h"
#include "DlgPoint.h"
#include "DlgRect.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRectTestView
IMPLEMENT_DYNCREATE(CRectTestView, CView)
BEGIN_MESSAGE_MAP(CRectTestView, CView)
//{{AFX_MSG_MAP(CRectTestView)
ON_COMMAND(ID_RECT_POINT, OnRectPoint)
ON_COMMAND(ID_RECT_RECT, OnRectRect)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CRectTestView construction/destruction
CRectTestView::CRectTestView()
{
// TODO: add construction code here
m_OldRect.SetRect(100, 100, 300, 200);
m_NewRect.SetRect(0, 0, 0, 0);
m_AddRect.SetRect(0, 0, 0, 0);
m_Point = CPoint(0, 0);
}
CRectTestView::~CRectTestView()
{
}
BOOL CRectTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CRectTestView drawing
void CRectTestView::OnDraw(CDC* pDC)
{
CRectTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->Rectangle(m_OldRect);
pDC->Rectangle(m_AddRect);
pDC->Rectangle(m_NewRect);
char temp[10];
CString strOldRect = "Old rect is: ";
itoa(m_OldRect.left,temp,10);
strOldRect += temp;
strOldRect += " ";
itoa(m_OldRect.top,temp,10);
strOldRect += temp;
strOldRect += " ";
itoa(m_OldRect.right,temp,10);
strOldRect += temp;
strOldRect += " ";
itoa(m_OldRect.bottom,temp,10);
strOldRect += temp;
CString strAddRect = "Add rect is: ";
itoa(m_AddRect.left,temp,10);
strAddRect += temp;
strAddRect += " ";
itoa(m_AddRect.top,temp,10);
strAddRect += temp;
strAddRect += " ";
itoa(m_AddRect.right,temp,10);
strAddRect += temp;
strAddRect += " ";
itoa(m_AddRect.bottom,temp,10);
strAddRect += temp;
CString strNewRect = "New rect is: ";
itoa(m_NewRect.left,temp,10);
strNewRect += temp;
strNewRect += " ";
itoa(m_NewRect.top,temp,10);
strNewRect += temp;
strNewRect += " ";
itoa(m_NewRect.right,temp,10);
strNewRect += temp;
strNewRect += " ";
itoa(m_NewRect.bottom,temp,10);
strNewRect += temp;
CString strPoint = "Point is: ";
itoa(m_Point.x,temp,10);
strPoint += temp;
strPoint += " ";
itoa(m_Point.y,temp,10);
strPoint += temp;
pDC->TextOut(500,30 ,strOldRect);
pDC->TextOut(500,50 ,strAddRect);
pDC->TextOut(500,70 ,strNewRect);
pDC->TextOut(500,90 ,strPoint);
}
/////////////////////////////////////////////////////////////////////////////
// CRectTestView printing
BOOL CRectTestView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CRectTestView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CRectTestView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CRectTestView diagnostics
#ifdef _DEBUG
void CRectTestView::AssertValid() const
{
CView::AssertValid();
}
void CRectTestView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CRectTestDoc* CRectTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRectTestDoc)));
return (CRectTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRectTestView message handlers
void CRectTestView::OnRectPoint()
{
// TODO: Add your command handler code here
CDlgPoint dlg;
if( dlg.DoModal()==IDOK)
{
m_Point = CPoint(dlg.m_nX, dlg.m_nY);
if(dlg.m_nRadio == 0)
{
m_NewRect = m_OldRect + m_Point;
}
else
{
m_NewRect = m_OldRect - m_Point;
}
}
Invalidate();
}
void CRectTestView::OnRectRect()
{
// TODO: Add your command handler code here
CDlgRect dlg;
if( dlg.DoModal()==IDOK)
{
m_AddRect = CRect(dlg.m_nLeft, dlg.m_nTop, dlg.m_nRight, dlg.m_nBottom);
if(dlg.m_nRadio == 0)
{
m_NewRect = m_OldRect + m_AddRect;
}
else if(dlg.m_nRadio == 1)
{
m_NewRect = m_OldRect;
m_NewRect -= m_AddRect;
}
else if(dlg.m_nRadio == 2)
{
m_NewRect = m_OldRect & m_AddRect;
}
else
{
m_NewRect = m_OldRect | m_AddRect;
}
}
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -