【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-GraphView.cpp,希望本篇文章对您学习有所帮助。
// GraphView.cpp : implementation of the CGraphView class
//
#include "stdafx.h"
#include "Graph.h"
#include "GraphDoc.h"
#include "GraphView.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGraphView
IMPLEMENT_DYNCREATE(CGraphView, CView)
BEGIN_MESSAGE_MAP(CGraphView, CView)
//{{AFX_MSG_MAP(CGraphView)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CGraphView construction/destruction
CGraphView::CGraphView()
{
// TODO: add construction code here
}
CGraphView::~CGraphView()
{
}
BOOL CGraphView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGraphView drawing
void CGraphView::OnDraw(CDC* pDC)
{
CGraphDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
int i;
//由于在OnDraw()函数中pDC是传入参数,
//所以不用CDC* pDC=GetDC()获取设备描述表指针。
//绘制一组彩色点
pDC->TextOut(20,20,"Point");
pDC->SetPixel(100,20,RGB(255,0,0));
pDC->SetPixel(110,20,RGB(0,255,0));
pDC->SetPixel(120,20,RGB(0,0,255));
pDC->SetPixel(120,20,RGB(255,255,0));
pDC->SetPixel(140,20,RGB(255,0,255));
pDC->SetPixel(150,20,RGB(0,255,255));
pDC->SetPixel(160,20,RGB(0,0,0));
//绘制直线
pDC->TextOut(20,60,"Line");
pDC->MoveTo(20,90);
pDC->LineTo(160,90);
//绘制折线
POINT polyline[4]={{70,240},{20,190},{70,190},{20,240}};
POINT polyPolyline[9]={{95,160},{120,185},{120,250},{145,160},{120,185},
{90,185},{150,185},{80,210},{160,210}};
DWORD dwPolyPoints[4]={3,2,2,2};
pDC->Polyline(polyline,4);
pDC->PolyPolyline(polyPolyline,dwPolyPoints,4);
//绘制贝齐尔曲线(Bezier)
POINT polyBezier[4]={{20,310},{60,240},{120,300},{160,330}};
pDC->PolyBezier(polyBezier,4);
//绘制圆,圆弧和椭圆
for(i=0;i<6;i++)
{
pDC->Arc(260-5*i,70-5*i,260+5*i,70+5*i,260+5*i,70,260+5*i,70);
}
for(i=3;i<6;i++)
{
pDC->Arc(260-10*i,70-10*i,260+10*i,70+10*i,
(int)260+10*i*cos(60*3.1415926/180),
(int)70+10*i*sin(60*3.1415926/180),
(int)260+10*i*cos(60*3.1415926/180),
(int)70-10*i*sin(60*3.1415926/180));
pDC->Arc(260-10*i,70-10*i,260+10*i,70+10*i,
(int)260-10*i*cos(60*3.1415926/180),
(int)70-10*i*sin(60*3.1415926/180),
(int)260-10*i*cos(60*3.1415926/180),
(int)70+10*i*sin(60*3.1415926/180));
}
pDC->Ellipse(260-50,200-30,260+50,200+30);
//绘制矩形和圆角矩形
pDC->Rectangle(190,270,250,310);
pDC->RoundRect(265,270,330,310,30,20);
//绘制玄形和扇形
pDC->Chord(360-70,70-70,360+70,70+70,
(int)360+70*cos(60*3.1415926/180),
(int)70+70*sin(60*3.1415926/180),
(int)360+70*cos(30*3.1415926/180),
(int)70-70*sin(30*3.1415926/180));
pDC->Pie(480-70,70-80,480+80,70+80,
(int)480+70*cos(60*3.1415926/180),
(int)70+70*sin(60*3.1415926/180),
(int)480+70*cos(30*3.1415926/180),
(int)70-70*sin(30*3.1415926/180));
//绘制多边形
POINT polygon[3]={{390,160},{430,220},{350,210}};
POINT polyPolygon[6]={{450,120},{550,320},{480,280},
{400,300},{550,320},{480,280}};
int polygonPoints[2]={3,3};
pDC->Polygon(polygon,3);
pDC->PolyPolygon(polyPolygon,polygonPoints,2);
}
/////////////////////////////////////////////////////////////////////////////
// CGraphView printing
BOOL CGraphView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGraphView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGraphView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGraphView diagnostics
#ifdef _DEBUG
void CGraphView::AssertValid() const
{
CView::AssertValid();
}
void CGraphView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGraphDoc* CGraphView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGraphDoc)));
return (CGraphDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGraphView message handlers
上一篇:
GraphShowerView.cpp
下一篇:
关于XX镇中小企业电子商务应用发展趋势的研究