📄 zgchartlib.h
字号:
DECLARE_DYNAMIC(CZgChartTipsWnd);
// Construction
public:
CZgChartTipsWnd();
// Attributes
public:
CZgChartTips *mp_ChartTips;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CZgChartTipsWnd)
protected:
//}}AFX_VIRTUAL
// Implementation
public:
BOOL CreateTipsWnd(CRect rect, CWnd *pParent);
virtual ~CZgChartTipsWnd();
// Generated message map functions
protected:
CWnd *mp_Parent;
BOOL SetTransparent(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
HMODULE m_hUserDll ; //DLL
//{{AFX_MSG(CZgChartTipsWnd)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
typedef struct STRU_CUTLINE_DATA
{
char szCutlineName[40]; //图例名称
COLORREF crCutlineColor; //图例颜色
UINT nLineWidth; //曲线宽度
CRect rcPos; //图例位置
BOOL bStatus; //图例状态
}CutlineData;
//////////////////////////////////////////////////////////////////////////
class CZgChartCutline
{
// Construction
public:
CZgChartCutline();
public:
void UpdateCutlinePara(COLORREF crColor, UINT nLineWidth, int nIndex);
BOOL GetCutlineStatusByIndex(int nIndex);
void ReverseStatus(int nIndex);
BOOL GetCutlineRectByIndex(CRect &rcPos, int nIndex);
BOOL GetCutlineColorInfoByIndex(COLORREF &crColor, UINT &nLineWidth, int nIndex);
BOOL GetCutlineInfoByIndex(CString &strName, COLORREF &crColor, int nIndex);
void ShowChartCutline(CDC *pDC, CRect &rcDraw);
BOOL AddChartCutline(char szName[], COLORREF crColor, UINT nLineWidth=2, BOOL bClearData=FALSE);
void EmptyData();
virtual ~CZgChartCutline();
protected:
void DrawCutline(CDC *pDC, CRect &rcDraw, CutlineData *pData);
void DrawAllCutline(CDC *pDC, CRect &rcClient);
CPtrList m_CutlineList;
};
//////////////////////////////////////////////////////////////////////////
#define IDD_DIALOG_LINE_SET 101
#define IDC_COMBO_LINEWIDTH 1038
#define IDC_BUTTON_LINECOLOR 1039
class CZgChartLineSetDlg : public CDialog
{
// Construction
public:
CZgChartLineSetDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CZgChartLineSetDlg)
enum { IDD = IDD_DIALOG_LINE_SET };
CColourPicker m_LineColor;
int mi_LineWidth;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CZgChartLineSetDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CZgChartLineSetDlg)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////////////////////////////
#define MAX_CURVE_COUNT 10 //最大曲线条数
typedef struct STRU_CHART_DATA
{
int nValueTime; //时间点
float fValue; //值
BOOL bValid; //是否有效
}ChartData;
class CZgChartView : public CWnd
{
// Construction
public:
CZgChartView();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CZgChartView)
public:
//}}AFX_VIRTUAL
// Implementation
public:
//设置时间间隔,可以不设置,但在获取数值会出现一些小问题
void SetTimeSpin(int nTimeSpin);
//保存当前曲线到指定位图文件
BOOL SaveChartToFile(CString &strFileName);
//打印当前曲线
void PrintChart(CDC *pDC);
//强制隐藏当前提示窗体
void HideTips();
//设置曲线标题文本
void SetTitleText(CString &strTitle);
//添加曲线数据信息
BOOL AddChartData(int nIndex, int nTime, float fValue, BOOL bValid=TRUE);
//设置纵向坐标的范围
void SetYValue(int nMin, int nMax);
//添加曲线类型
BOOL AddChartCutline(char szName[], COLORREF crColor, UINT nLineWidth=2, BOOL bClearData=FALSE);
//日期设置,间隔时天的倍数,最好能够被24整除
void SetXDate(int nStart, int nStop);
//创建曲线显示窗体
BOOL CreateChartView(CWnd *pParentWnd, CRect &rect);
virtual ~CZgChartView();
// Generated message map functions
protected:
CZgChartCutline m_ChartCutline; //曲线图例
CZgChartTips m_ChartTips; //曲线提示
int mi_SpinX; //X轴等分大小
int mi_SpinY; //Y轴等分大小
int mi_MarginTop; //曲线顶部间隔
int mi_MarginBottom; //曲线底部间隔
int mi_MarginLeft; //曲线左边间隔
int mi_MarginRight; //曲线右边间隔
int mi_SpinWidth; //X轴宽度
int mi_SpinHeight; //Y轴高度
COLORREF m_crTitleText; //标题文本颜色
CString m_strTitleText; //标题文本
UINT mi_TitleAlign; //标题文本对齐类型:左,中,右
COLORREF m_crDate; //显示提示中时间的颜色
COLORREF m_crBackground;//曲线背景颜色
COLORREF m_crScaleText; //刻度文本颜色
COLORREF m_crLinePoint; //点线颜色
UINT mi_TimerMove; //定时器
CPoint m_ptSave; //坐标保存点
int mi_MinX; //X轴最小值
int mi_MaxX; //X轴最大值
int mi_MinY; //Y轴最小值
int mi_MaxY; //Y轴最大值
int mi_DayCount; //天数
CFont m_FontText; //文本字体
CFont m_FontTitle; //标题文字字体
CPen m_PenCoordinate; //坐标轴
CPen m_PenArrow; //坐标轴箭头
CPen m_PenSpinLine; //坐标轴分割线
CPen m_PenPosLine; //鼠标在曲线中的定位线
CRect m_rcClient; //整个客户,在ONSIZE事件中更新
CRect m_rcCurve; //曲线
int mi_CurveCount; //曲线条数
BOOL mi_DrawLineSmooth; //是否使用Bezier来平滑画线
BOOL mi_TipsWithMouse; //显示提示是否跟随光标
BOOL mi_DrawLineVertical;//非Bezier来平滑画线时候是否采用直方图方式
CPtrList m_DataList[MAX_CURVE_COUNT]; //最多十条曲线的数据保存点
int mi_TimeSpin; //数据时间间隔
protected:
int mi_CurDataIndexSave;
CZgChartTipsWnd m_ChartTipsWnd;
BOOL SaveBitmapToFile(HBITMAP hBitmap , CString &strFileName);
void DrawYFloatTextFromValue(CDC *pDC, CPoint ptText, float fValue);
void DrawCutline(CDC* pDC, CRect &rcClient);
void DrawCrossLine(CDC *pDC);
void DrawChartTips(CDC *pDC);
int GetDateStringByX(CString &strDate, int nChartIndex);
void DatePointToChartPoint(CPoint &ptChart, int nTime, float fValue);
void DrawSingleCurveSmooth(CDC *pDC, int nIndex, CRect &rcDraw);
void DrawSingleCurveNoSmooth(CDC *pDC, int nIndex, CRect &rcDraw);
void GetXStringByPos(CString &strText);
float GetYValueByPos();
void DrawFloatTextFromValue(CDC *pDC, CPoint ptText, float fValue);
void DrawDateTextFromValue(CDC *pDC, CPoint ptText, int nValue);
void DrawFloatTextFromValue(CDC *pDC, CPoint ptText, int nValue);
void DrawChartTitle(CDC *pDC, CRect &rcDraw, BOOL bPrint=FALSE);
void DrawCurve(CDC *pDC, CRect &rcDraw);
void DrawCoordinate(CDC *pDC, CRect &rcDraw);
//{{AFX_MSG(CZgChartView)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -