资源简介
自己写的一个曲线绘制类,使用简单,功能强大。为了演示方便,所有功能都在右键菜单中实现。写的时间比较短,测试也不是太完善。不过我自己已经把它用于工业控制软件中了。欢迎大家下载使用,可任意修改,有好的想法一定告诉我。
主要实现的功能:
曲线绘制,动态曲线,静态曲线,多条曲线,缩放,移动,颜色,绘图方向,曲线数据读取,数据存盘,曲线存为Bmp
等。
代码片段和文件信息
// Chart.cpp : implementation file
//
#include “stdafx.h“
#include “TestMyChart.h“
#include “Chart.h“
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChart
//##ModelId=48A145880178
CChart::CChart()
{
m_bDrawReverseX = false; //绘图方向
m_bDrawReverseY = false; //绘图方向
m_bShowMenum = true;
m_bAllCurveSamebase = false;
m_bHideUnselectCurve = false;
m_bShowDataFlowMouse = false; //取数据时是否让数据跟随鼠标显示
m_crBackColor = RGB(0045);
m_crGridColor = RGB(120120120);
m_crframeColor = RGB(255255255);
m_brushBack.CreateSolidBrush(m_crBackColor) ;
m_brushGrid.CreateSolidBrush(m_crGridColor) ;
m_CurveMap.RemoveAll();
m_ptMaxPos.InitPoint(0.00.0);
m_ptMinPos.InitPoint(0.00.0);
m_ptZoomOffset.InitPoint(0.00.0);
m_ptMoveOffset.InitPoint(0.00.0);
m_rectClient.SetRectEmpty();
m_rectPlot.SetRectEmpty();
m_ptMargin.x = 10;
m_ptMargin.y = 10;
m_dVerticalFactor = 1.0;
m_dHorizontalFactor = 1.0;
m_iControlMode = CURVE_MOVE;
m_bLeftButtonDown = false;
m_iVerticalControlMode = false; //默认是水平控制模式(指管轮操作模式的移动即缩放功能)
m_recMouseSelect.SetRectEmpty();
m_pCurSelCurveObj = NULL;
}
//##ModelId=48A145880186
CChart::~CChart()
{
POSITION pos=m_CurveMap.GetStartPosition();
CString strKey;
Cobject* pOb;
while(pos)
{
m_CurveMap.GetNextAssoc(posstrKeypOb);
delete pOb;
pOb = NULL;
}
}
BEGIN_MESSAGE_MAP(CChart CWnd)
//{{AFX_MSG_MAP(CChart)
ON_WM_SIZE()
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_MOUSEWHEEL()
ON_WM_RBUTTONDOWN()
ON_WM_CONTEXTMENU()
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
ON_UPDATE_COMMAND_UI_RANGE(999010010OnUpdateMenuState)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChart message handlers
//##ModelId=48ACE0A6036B
BOOL CChart::Create(DWORD dwstyle const RECT &rect CWnd *pParentWnd UINT nID)
{
BOOL result ;
static CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW) ;
result = CWnd::CreateEx(WS_THICKframe
className NULL dwstyle
rect.left rect.toprect.right-rect.left rect.bottom-rect.top
pParentWnd->GetSafeHwnd() (HMENU)nID) ;
if (result != 0)
{
this->SetMargin();
InvalidateCtrl();
this->DrawGrid();
}
return result ;
}
//##ModelId=48A14589009E
BOOL CChart::InvalidateCtrl() //
{
CClientDC dc(this) ;
//创建绘制网格的内存绘图对象
m_dcGrid.DeleteDC();
m_dcGrid.CreateCompatibleDC(&dc) ;
m_bitmapBackground.Deleteobject();
m_bitmapBackground.CreateCompatibleBitmap(&dc m_nClientWidth m_nClientHeight) ;
m_pbitmapOldBackground = m_dcGrid.Selectobject(&m_b
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 48435 2008-09-23 21:24 TestMyChart\Chart.cpp
文件 7790 2008-09-26 01:52 TestMyChart\Chart.h
....... 26350 2008-09-22 17:09 TestMyChart\CurveObj.cpp
文件 8186 2008-09-26 01:52 TestMyChart\CurveObj.h
文件 159 2008-09-23 08:54 TestMyChart\mssccprj.scc
....... 3669 2008-09-18 12:22 TestMyChart\ReadMe.txt
....... 1078 2008-09-18 12:22 TestMyChart\res\TestMyChart.ico
....... 403 2008-09-18 12:22 TestMyChart\res\TestMyChart.rc2
....SH. 119 2008-09-23 08:54 TestMyChart\res\vssver2.scc
文件 1842 2008-09-23 20:38 TestMyChart\resource.h
....... 213 2008-09-18 12:22 TestMyChart\StdAfx.cpp
....... 999 2008-09-18 12:22 TestMyChart\StdAfx.h
文件 37264 2008-09-23 20:38 TestMyChart\TestMyChart.aps
文件 1592 2008-09-26 01:55 TestMyChart\TestMyChart.clw
....... 2178 2008-09-18 12:22 TestMyChart\TestMyChart.cpp
....... 4597 2008-09-18 12:22 TestMyChart\TestMyChart.dsp
文件 648 2008-09-19 20:22 TestMyChart\TestMyChart.dsw
....... 1459 2008-09-18 12:22 TestMyChart\TestMyChart.h
文件 132096 2008-09-26 01:56 TestMyChart\TestMyChart.ncb
文件 51712 2008-09-26 01:56 TestMyChart\TestMyChart.opt
文件 258 2008-09-26 01:56 TestMyChart\TestMyChart.plg
文件 6123 2008-09-23 20:38 TestMyChart\TestMyChart.rc
文件 7140 2008-09-26 01:53 TestMyChart\TestMyChartDlg.cpp
文件 1898 2008-09-23 20:38 TestMyChart\TestMyChartDlg.h
....... 2696 2008-09-18 12:22 TestMyChart\threadtrace.cpp
....... 1566 2008-09-18 12:22 TestMyChart\threadtrace.h
....SH. 518 2008-09-23 17:19 TestMyChart\vssver2.scc
目录 0 2008-09-18 12:22 TestMyChart\res
目录 0 2008-09-26 01:56 TestMyChart
----------- --------- ---------- ----- ----
............此处省略2个文件信息
- 上一篇:池塘夜降彩色雨
- 下一篇:信号FFT变换及绘图
评论
共有 条评论