📄 test8view.cpp
字号:
// test8View.cpp : implementation of the CTest8View class
//
#include "stdafx.h"
#include "test8.h"
#include "test8Doc.h"
#include "test8View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTest8View
IMPLEMENT_DYNCREATE(CTest8View, CView)
BEGIN_MESSAGE_MAP(CTest8View, CView)
//{{AFX_MSG_MAP(CTest8View)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CTest8View construction/destruction
CTest8View::CTest8View()
{
// TODO: add construction code here
}
CTest8View::~CTest8View()
{
}
BOOL CTest8View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTest8View drawing
void CTest8View::OnDraw(CDC* pDC)
{
CTest8Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int x0,y0;
int x1,y1;
x0=10;
y0=10;
x1=455;
y1=400;
CPen MyPen,*OldPen;
MyPen.CreatePen(PS_SOLID,1,RGB(0,255,0));
OldPen=pDC->SelectObject(&MyPen);
pDC->MoveTo(x0,y0);
pDC->LineTo(x1,y1);
pDC->SelectObject(OldPen);//加色
MyPen.DeleteObject();
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(10,10,"Bresenham Line");
///////////////////////////////////////////////////////
int x,y;
x=x0+128;
y=y0;//起点
int x2,y2;
x2=x1+128;
y2=y1;//终点
float d=0;
float k,b;
k=(float)(y2-y)/(float)(x2-x);
b=(float)y-k*(float)x;
COLORREF rgb1, rgb2;
while(x<=x2)
{
rgb1=RGB(d*255,d*255,d*255);
rgb2=RGB((1-d)*255,(1-d)*255,(1-d)*255);
pDC->SetPixel(x,y,rgb1);
pDC->SetPixel(x,y+1,rgb2);
d=d+k;
if(d>1.0)
{
x+=1;
y+=1;
d=d-1.0;
}
else
x+=1;
}
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(10+128,10,"距离反走样直线");
}
/////////////////////////////////////////////////////////////////////////////
// CTest8View printing
BOOL CTest8View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTest8View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTest8View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTest8View diagnostics
#ifdef _DEBUG
void CTest8View::AssertValid() const
{
CView::AssertValid();
}
void CTest8View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTest8Doc* CTest8View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTest8Doc)));
return (CTest8Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTest8View message handlers
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -