CRect rect;
this->GetClientRect(rect);
pDC->Ellipse(rect);
// DDALineView.cpp : implementation of the CDDALineView class
//
#include “stdafx.h”
#include “DDALine.h”
#include “DDALineDoc.h”
#include “DDALineView.h”
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = FILE;
#endif
/
// CDDALineView
IMPLEMENT_DYNCREATE(CDDALineView, CView)
BEGIN_MESSAGE_MAP(CDDALineView, CView)
//{{AFX_MSG_MAP(CDDALineView)
// 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()
/
// CDDALineView construction/destruction
CDDALineView::CDDALineView()
{
// TODO: add construction code here
}
CDDALineView::~CDDALineView()
{
}
BOOL CDDALineView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/
// CDDALineView drawing
void CDDALineView::OnDraw(CDC* pDC)
{
CDDALineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/
// CDDALineView printing
BOOL CDDALineView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDDALineView::OnBeginPrinting(CDC* /pDC/, CPrintInfo* /pInfo/)
{
// TODO: add extra initialization before printing
}
void CDDALineView::OnEndPrinting(CDC* /pDC/, CPrintInfo* /pInfo/)
{
// TODO: add cleanup after printing
}
/
// CDDALineView diagnostics
#ifdef _DEBUG
void CDDALineView::AssertValid() const
{
CView::AssertValid();
}
void CDDALineView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDDALineDoc* CDDALineView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDDALineDoc)));
return (CDDALineDoc*)m_pDocument;
}
#endif //_DEBUG
/
// CDDALineView message handlers
void CDDALineView::ddaline(CDC*pDC,int x0,int y0,int x1,int y1,COLORREF color)
{
int length,i;
double x,y,dx,dy;
length=abs(x1-x0);
if(abs(y1-y0)>length)
length=abs(y1-y0);
dx=(x1-x0)/length;
dy=(y1-y0)/length;
x=x0+0.5;y=y0+0.5;
for(i=1;i<=length;i++)
{
pDC->SetPixel((int)x,(int)y,color);
x=x+dx;y=y+dy;
}
}
void CDDALineView::OnDraw(CDC* pDC)
{
CDDALineDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
ddaline(pDC,100,100,400,100,RGB(255,0,0));
ddaline(pDC,400,100,400,400,RGB(0,255,0));
ddaline(pDC,400,400,100,400,RGB(0,0,255));
ddaline(pDC,100,400,100,100,RGB(255,255,0));
ddaline(pDC,100,100,400,400,RGB(255,0,255));
ddaline(pDC,100,400,400,100,RGB(0,255,255));
}
实验三
1.
void CMidPointCircleView::MidpointCircle(CDC pDC, int x0, int y0, int r, COLORREF color)
{
int x,y;
float d;
x=0,y=r,d=1.25-r;
CirPot(pDC,x0,y0,x,y,color);
while(x<=y)
{
if(d<0)
{
d+=2x+3;x++;
}
else
{
d+=2*(x-y)+5;
x++;y--;
}
CirPot(pDC,x0,y0,x,y,color);
}
}
int CMidPointCircleView::CirPot(CDC *pDC, int x0, int y0, int x, int y, COLORREF color)
{
pDC->SetPixel((x0+x),(y0+y),color);
pDC->SetPixel((x0+y),(y0+x),color);
pDC->SetPixel((x0+y),(y0-x),color);
pDC->SetPixel((x0+x),(y0-y),color);
pDC->SetPixel((x0-x),(y0-y),color);
pDC->SetPixel((x0-y),(y0-x),color);
pDC->SetPixel((x0-y),(y0+x),color);
pDC->SetPixel((x0-x),(y0+y),color);
return 0;
}
void CMidPointCircleView::OnDraw(CDC* pDC)
{
CMidPointCircleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
MidpointCircle(pDC,100,100,10,RGB(255,0,0));
MidpointCircle(pDC,500,300,60,RGB(255,0,0));
}