基本信息
源码名称:c++ 绘制坐标(支持象限和刻度)
源码大小:9.59M
文件格式:.zip
开发语言:C/C++
更新时间:2021-04-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
绘制坐标,带有刻度并且可以根据需求设置所在 象限内容
// 坐标View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "坐标.h"
#include "坐标Doc.h"
#include "坐标View.h"
#include "Setting.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(ID_PLANFIY, OnPlanfiy)
ON_COMMAND(ID_REV, OnRev)
ON_COMMAND(ID_SEVEA, OnSevea)
ON_COMMAND(ID_REGION, OnRegion)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
m_Button=0;
m_region=160;
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rect;
GetClientRect(&rect);//首先获得视图的区域
//下面开始画坐标系的x轴和y轴
pDC->MoveTo(rect.left 100,rect.bottom-100);
pDC->LineTo(rect.right-100,rect.bottom-100);
pDC->MoveTo(rect.left 100,rect.bottom-100);
pDC->LineTo(rect.left 100,rect.top 100);
//下面画x轴和y轴上的短线
int xlen=rect.right-rect.left-200;
int ylen=rect.top-rect.bottom 200;//这里ylen是个负数
CPoint CurP;//保存当前点的坐标
//下面是画x坐标轴上的短线
//画前要保证当前点在坐标原点
CurP.x=rect.left 100;
CurP.y=rect.bottom-100;//使当前原点为原点值
pDC->MoveTo(rect.left 100,rect.bottom-100);
for(int i=0;i<10;i )
{
CurP.x =xlen/10; //将x轴分为10个小段
pDC->MoveTo(CurP.x,CurP.y);
pDC->LineTo(CurP.x,CurP.y-5);
}
//下面画y坐标轴上的短线
//首先还是要保证当前点在坐标原点
CurP.x=rect.left 100;
CurP.y=rect.bottom-100;//为当前原点赋值
pDC->MoveTo(rect.left 100,rect.bottom-100);
for(int i=0;i<10;i )
{
CurP.y =ylen/10;
pDC->MoveTo(CurP.x,CurP.y);
pDC->LineTo(CurP.x 5,CurP.y);
}
//下面画坐标系上面的数字间隔
//还是要保证当前点在坐标原点
CurP.x=rect.left 100;
CurP.y=rect.bottom-100;//为当前原点赋值
pDC->MoveTo(rect.left 100,rect.bottom-100);
int maxX,maxY;//记录x轴和y轴上的最大值,认为最小值是0
int xSeg,ySeg;//记录x轴和y轴上每一段分隔的长度
maxX = m_region;
switch(m_Button) {
case 0: maxY=2000;
break;
case 1: maxY=100;
break;
case 2: maxY=4100;
break;
}
xSeg=maxX/10;
ySeg=maxY/10;
CString Temp; //存放临时坐标上的数值
pDC->TextOut(rect.left 100-10,rect.bottom-100 5,"0");//画原点O
for(int i=0;i<10;i )
{
Temp.Format("%d",xSeg);
CurP.x =xlen/10;
xSeg =maxX/10;
pDC->TextOut(CurP.x,CurP.y 5,Temp);
}
//再次要保证当前点在坐标原点
CurP.x=rect.left 100;
CurP.y=rect.bottom-100;//为当前原点赋值
pDC->MoveTo(rect.left 100,rect.bottom-100);
for(int i=0;i<10;i )
{
Temp.Format("%d",ySeg);
CurP.y =ylen/10;
ySeg =maxY/10;
pDC->TextOut(CurP.x-50,CurP.y,Temp);
}
int x;int y;
switch(m_Button) {
case 0:
x = 25;
y = 120;
pDC->TextOut(x, y, "待飞距(km)");
break;
case 1:
x = 25;
y = 120;
pDC->TextOut(x, y, "节风门(%)");
break;
case 2:
x = 25;
y = 120;
pDC->TextOut(x, y, "转速(r/s)");
break;
}
x =700;
y = 430;
pDC->TextOut(x, y, "时间(ms)");
}
/////////////////////////////////////////////////////////////////////////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnPlanfiy()
{
// TODO: Add your command handler code here
m_Button=0;
Invalidate();
}
//void CMyView::OnFileSave()
//{
// // TODO: Add your command handler code here
// m_Button=1;
// Invalidate();
//}
void CMyView::OnRev()
{
// TODO: Add your command handler code here
m_Button=2;
Invalidate();
}
void CMyView::OnSevea()
{
// TODO: Add your command handler code here
m_Button=1;
Invalidate();
}
void CMyView::OnRegion()
{
// TODO: Add your command handler code here
CSetting dlg;
if(IDOK==dlg.DoModal())
{
m_region=dlg.m_region;
}
Invalidate();
}