📄 test10view.cpp
字号:
// test10View.cpp : implementation of the CTest10View class
//
#include "stdafx.h"
#include "test10.h"
#include "test10Doc.h"
#include "test10View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTest10View
IMPLEMENT_DYNCREATE(CTest10View, CView)
BEGIN_MESSAGE_MAP(CTest10View, CView)
//{{AFX_MSG_MAP(CTest10View)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CTest10View construction/destruction
CTest10View::CTest10View()
{
// TODO: add construction code here
}
CTest10View::~CTest10View()
{
}
BOOL CTest10View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTest10View drawing
void CTest10View::OnDraw(CDC* pDC)
{
CTest10Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int x1,x2,y1,y2;//起点和终点的坐标
x1=90;
y1=90;
x2=550;
y2=400;
int dx,dy;
int x,y,p;
int const1,const2;
int inc,tmp;
dx=x2-x1;
dy=y2-y1;
int N=abs(x2-x1);
float delta=255.0/(float)N;
float color=255.0;
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((int)color,0,0));
while(x<x2)
{
x++;
color-=delta;
if(p<0)
p+=const1;
else
{
y+=inc;
p+=const2;
}
pDC->SetPixel(x,y,RGB((int)color,0,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((int)color,0,0));
while(y<y2)
{
y++;
color-=delta;
if(p<0)
p+=const1;
else
{
x+=inc;
p+=const2;
}
pDC->SetPixel(x,y,RGB((int)color,0,0));
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CTest10View printing
BOOL CTest10View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTest10View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTest10View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTest10View diagnostics
#ifdef _DEBUG
void CTest10View::AssertValid() const
{
CView::AssertValid();
}
void CTest10View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTest10Doc* CTest10View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTest10Doc)));
return (CTest10Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTest10View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -