⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test2view.cpp

📁 mfc算法基本原理 初学者的良药 开发者的天堂
💻 CPP
字号:
// test2View.cpp : implementation of the CTest2View class
//

#include "stdafx.h"
#include "test2.h"

#include "test2Doc.h"
#include "test2View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTest2View

IMPLEMENT_DYNCREATE(CTest2View, CView)

BEGIN_MESSAGE_MAP(CTest2View, CView)
	//{{AFX_MSG_MAP(CTest2View)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CTest2View construction/destruction

CTest2View::CTest2View()
{
	// TODO: add construction code here

}

CTest2View::~CTest2View()
{
}

BOOL CTest2View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View drawing

void CTest2View::OnDraw(CDC* pDC)
{
	CTest2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
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));
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View printing

BOOL CTest2View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTest2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTest2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTest2View diagnostics

#ifdef _DEBUG
void CTest2View::AssertValid() const
{
	CView::AssertValid();
}

void CTest2View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CTest2Doc* CTest2View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTest2Doc)));
	return (CTest2Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTest2View message handlers

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -