实例介绍
【实例简介】
绘制坐标,带有刻度并且可以根据需求设置所在 象限内容
【实例截图】
【核心代码】
// 坐标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(); }
标签: 坐标
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论