📄 zgchartlib.h
字号:
#ifndef ZGCHARTLIB_H
#define ZGCHARTLIB_H
//ZgChartLib Copyright 2004-2005 ZhuGang
//名 称:曲线显示库
//头文件:ZgChartLib.h
//库文件:ZgChartLib.lib
//////////////////////////////////////////////////////////////////////////
//功 能:类似mschart
//说 明1:横向坐标为时间值
//说 明2:纵向坐标为数值(float)
//功能详细说明如下
//1:时间相关联数据的显示
//2:最多10条曲线同时显示
//3:曲线信息保存到位图文件
//4:曲线信息打印:需要传入打印DC,在例子程序中我给出了详细的代码
//5:曲线显示时动态调整是否显示(左键点击曲线图例)
//6:曲线当前鼠标位置数据半透明显示(Windows2000以上支持)
//7:曲线纵向数值显示
//8:曲线动态调整颜色和线宽(右键点击曲线图例,必须保留对话框资源IDD_DIALOG_LINE_SET,否则不能使用)
//一些说明:由于这个库封装成静态Lib,对话框资源的获取出现问题,本人还没有找到方法解决,但如果使用DLL就没有问题/
//如果有人知道如何获取静态Lib中的资源方法,谢谢教教我
//////////////////////////////////////////////////////////////////////////
//大家可以随便使用本链接库,但请保留这些说明文字
//如有问题和BUG请与我联系:sonystone@tom.com, sonystone@163.com
//如有需要C++源代码,请与本人联系
//请参考例子程序
//请不要修改以下代码,否则出现错误
//////////////////////////////////////////////////////////////////////////
class CZgMemDC : public CDC
{
CZgMemDC(CDC* pDC, const CRect* pRect = NULL);
~CZgMemDC();
};
//////////////////////////////////////////////////////////////////////////
class CZgBitmap : public CBitmap
{
public:
CZgBitmap();
virtual ~CZgBitmap();
};
//////////////////////////////////////////////////////////////////////////
// CColourPopup messages
#define CPN_SELCHANGE WM_USER + 1001 // Colour Picker Selection change
#define CPN_DROPDOWN WM_USER + 1002 // Colour Picker drop down
#define CPN_CLOSEUP WM_USER + 1003 // Colour Picker close up
#define CPN_SELENDOK WM_USER + 1004 // Colour Picker end OK
#define CPN_SELENDCANCEL WM_USER + 1005 // Colour Picker end (cancelled)
// forward declaration
class CColourPicker;
// To hold the colours and their names
typedef struct {
COLORREF crColour;
TCHAR *szName;
} ColourTableEntry;
/////////////////////////////////////////////////////////////////////////////
// CColourPopup window
class CColourPopup : public CWnd
{
// Construction
public:
CColourPopup();
CColourPopup(CPoint p, COLORREF crColour, COLORREF crDefaultColour, CWnd* pParentWnd,
LPCTSTR szDefaultText = NULL, LPCTSTR szCustomText = NULL);
void Initialise();
void SetDefaultColor(COLORREF crColour) { m_crDefaultColour = crColour; }
// Attributes
public:
// Operations
public:
BOOL Create(CPoint p, COLORREF crColour, CWnd* pParentWnd,
LPCTSTR szDefaultText = NULL, LPCTSTR szCustomText = NULL);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColourPopup)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
// Implementation
public:
void SetDefaultColour(COLORREF crDefaultColour);
virtual ~CColourPopup();
protected:
BOOL GetCellRect(int nIndex, const LPRECT& rect);
void FindCellFromColour(COLORREF crColour);
void SetWindowSize();
void CreateToolTips();
void ChangeSelection(int nIndex);
void EndSelection(int nMessage);
void DrawCell(CDC* pDC, int nIndex);
COLORREF GetColour(int nIndex) { return m_crColours[nIndex].crColour; }
LPCTSTR GetColourName(int nIndex) { return m_crColours[nIndex].szName; }
int GetIndex(int row, int col) const;
int GetRow(int nIndex) const;
int GetColumn(int nIndex) const;
// protected attributes
protected:
static ColourTableEntry m_crColours[];
int m_nNumColours;
int m_nNumColumns, m_nNumRows;
int m_nBoxSize, m_nMargin;
int m_nCurrentSel;
int m_nChosenColourSel;
CString m_strDefaultText;
CString m_strCustomText;
CRect m_CustomTextRect, m_DefaultTextRect, m_WindowRect;
CFont m_Font;
CPalette m_Palette;
COLORREF m_crInitialColour, m_crColour;
COLORREF m_crDefaultColour;
CToolTipCtrl m_ToolTip;
CWnd* m_pParent;
// Generated message map functions
protected:
//{{AFX_MSG(CColourPopup)
afx_msg void OnNcDestroy();
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg BOOL OnQueryNewPalette();
afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnActivateApp(BOOL bActive, HTASK hTask);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////////////////////////////
void AFXAPI DDX_ColourPicker(CDataExchange *pDX, int nIDC, COLORREF& crColour);
/////////////////////////////////////////////////////////////////////////////
// CColourPicker window
#define CP_MODE_TEXT 1 // edit text colour
#define CP_MODE_BK 2 // edit background colour (default)
class CColourPicker : public CButton
{
// Construction
public:
CColourPicker();
DECLARE_DYNCREATE(CColourPicker);
// Attributes
public:
COLORREF GetColour();
void SetColour(COLORREF crColour);
void SetDefaultText(LPCTSTR szDefaultText);
void SetCustomText(LPCTSTR szCustomText);
void SetTrackSelection(BOOL bTracking = TRUE) { m_bTrackSelection = bTracking; }
BOOL GetTrackSelection() { return m_bTrackSelection; }
void SetSelectionMode(UINT nMode) { m_nSelectionMode = nMode; }
UINT GetSelectionMode() { return m_nSelectionMode; };
void SetBkColour(COLORREF crColourBk);
COLORREF GetBkColour() { return m_crColourBk; }
void SetTextColour(COLORREF crColourText);
COLORREF GetTextColour() { return m_crColourText;}
//void SetDefaultColour(COLORREF crColour) { m_crColourBk = m_crColourText = crColour; }
void SetDefaultColour(COLORREF crColour) { m_crDefaultBkColour = crColour; }
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CColourPicker)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CColourPicker();
protected:
void SetWindowSize();
// protected attributes
protected:
BOOL m_bActive, // Is the dropdown active?
m_bTrackSelection; // track colour changes?
COLORREF m_crColourBk;
COLORREF m_crColourText;
UINT m_nSelectionMode;
CRect m_ArrowRect;
CString m_strDefaultText;
CString m_strCustomText;
COLORREF m_crDefaultColour;
COLORREF m_crDefaultBkColour;
// Generated message map functions
protected:
//{{AFX_MSG(CColourPicker)
afx_msg BOOL OnClicked();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG
afx_msg LONG OnSelEndOK(UINT lParam, LONG wParam);
afx_msg LONG OnSelEndCancel(UINT lParam, LONG wParam);
afx_msg LONG OnSelChange(UINT lParam, LONG wParam);
DECLARE_MESSAGE_MAP()
};
//////////////////////////////////////////////////////////////////////////
typedef struct STRU_TIPSHOW_DATA
{
CString strTipsText; //提示文本
COLORREF crTipsColor; //提示文本颜色
}TipShowData;
//////////////////////////////////////////////////////////////////////////
class CZgChartTips
{
public:
CZgChartTips();
virtual ~CZgChartTips();
protected:
void DrawTips(CDC *pDC, CRect &rcDraw, TipShowData *pData);
void DrawAllTips(CDC *pDC, CRect &rcDraw);
BOOL MakeChartTips(CDC *pDC);
CZgBitmap m_BitmapTips;
CSize m_szMaxText;
CPtrList m_TipsList;
CSize m_szBitmap;
CFont m_FontText;
};
//////////////////////////////////////////////////////////////////////////
class CZgChartTipsWnd : public CWnd
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -