📄 test1view.cpp
字号:
// test1View.cpp : implementation of the CTest1View class
//
#include "stdafx.h"
#include "test1.h"
#include "test1Doc.h"
#include "test1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTest1View
IMPLEMENT_DYNCREATE(CTest1View, CView)
BEGIN_MESSAGE_MAP(CTest1View, CView)
//{{AFX_MSG_MAP(CTest1View)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CTest1View construction/destruction
CTest1View::CTest1View()
{
// TODO: add construction code here
}
CTest1View::~CTest1View()
{
}
BOOL CTest1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTest1View drawing
void CTest1View::OnDraw(CDC* pDC)
{
CTest1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int x1,x2,y1,y2;//起点和终点的坐标
x1=100;
y1=20;
x2=300;
y2=50;
int dx,dy;//横纵坐标的距离
int x,y,p;
int const1,const2;
int inc,tmp;
dx=x2-x1;
dy=y2-y1;
if(dx*dy>=0)
inc=1;//准备x或y的单位递变值
else inc=-1;
if(abs(dx)>abs(dy))
{
if(dx<0)
{
tmp=x1;
x1=x2;
x2=tmp;
tmp=y1;
y1=y2;
y2=tmp;
dx=-dx;
dy=-dy;
}
p=2*dy-dx;
const1=2*dy;
const2=2*(dy-dx);
x=x1;
y=y1;
pDC->SetPixel(x, y, RGB(0,255,0));
while(x<x2)
{
x++;
if(p<0)
p+=const1;
else
{
y+=inc;
p+=const2;
}
pDC->SetPixel(x, y, RGB(0,255,0));
}
}
else
{
if(dy<0)
{
tmp=x1;
x1=x2;
x2=tmp;
tmp=y1;
y1=y2;
y2=tmp;
dx=-dx;
dy=-dy;
}
p=2*dx-dy;
const1=2*dx;
const2=2*(dx-dy);
x=x1;
y=y1;
pDC->SetPixel(x, y, RGB(0,255,0));
while(y<y2)
{
y++;
if(p<0)
p+=const1;
else
{
x+=inc;
p+=const2;
}
pDC->SetPixel(x,y,RGB(0,255,0));
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CTest1View printing
BOOL CTest1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTest1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTest1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTest1View diagnostics
#ifdef _DEBUG
void CTest1View::AssertValid() const
{
CView::AssertValid();
}
void CTest1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTest1Doc* CTest1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTest1Doc)));
return (CTest1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTest1View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -