⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2dpushgraph.h

📁 完成MOTOBUS通信
💻 H
字号:
/* ===================================================================

C2DPushGraph Control (2DPushGraph.h and 2DPushGraph.cpp)

Author:  Stuart Konen
Contact: skonen@gmail.com (Job information welcome)

Description: A push graph control similiar to the graph control located
in Microsoft's Task Manager.

====================================================================*/


#if !defined(AFX_2DPUSHGRAPH_H_INCLUDED)
#define AFX_2DPUSHGRAPH_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#include <windows.h>
#include "afxtempl.h"

/////////////////////////////////////////////////////////////////////////////
// C2DPushGraph window


// ===================================================================

struct GraphColor
{	
	GraphColor() { bRed = bGreen = bBlue = 0; }

	operator COLORREF() { return RGB(bRed, bGreen, bBlue); }
	BYTE bRed, bGreen, bBlue;
};


// ===================================================================

struct PushGraphLine
{
	PushGraphLine(UINT uiLineID)
	{
		crLine     = RGB(0, 255, 0);
		uiID       = uiLineID;
		bShowAsBar = false;
	}

	COLORREF crLine;
	UINT     uiID;
	bool     bShowAsBar;

	CArray<int, double> aMagnitudes;	
};


// ===================================================================

class C2DPushGraph : public CWnd
{
public:
	C2DPushGraph();
	virtual ~C2DPushGraph();
	
	bool CreateFromStatic( UINT nStaticID, CWnd* pParent );


	/* Functions that retrieve attributes */
	
	LPCTSTR   GetLabelForMax() const;
	LPCTSTR   GetLabelForMin() const;


	COLORREF  GetBGColor()   const;	
	COLORREF  GetGridColor() const;
	COLORREF  GetLineColor( UINT uiLineID );
	COLORREF  GetTextColor() const;	

	int       GetGridSize()  const;
	int       GetMaxPeek()   const;
	int       GetMinPeek()   const;

// 	int    m_nPeekOffset;
// 	int    m_nMoveOffset;


	unsigned short GetInterval() const;	


	/* Functions that set attributes */

	void SetBGColor(COLORREF crColor);
	void SetGridColor(COLORREF crColor);
	void SetTextColor(COLORREF crColor);
	void SetGridSize( unsigned short usWidthAndHeight );
	void SetMaxPeek(int nMax);
	void SetMinPeek(int nMin);
	void SetPeekRange(int nMin, int nMax);
	void SetLabelForMax( LPCTSTR lpszLabel );
	void SetLabelForMin( LPCTSTR lpszLabel );
	
	
	void SetInterval( unsigned short usInterval );
	bool SetLineColor( COLORREF crColor, UINT uiLineID );

	
	/* Line control functions */
	
	bool    AddLine( UINT uiLineID, COLORREF crColor );
	void    RemoveLine( UINT uiLineID );
	bool    Push( double nMagnitude, UINT uiLineID );
	void    ShowAsBar( UINT uiLineID, bool bAsBar );
	void    Update();	


	/* Visibility Functions */

	inline void ShowGrid( bool bShow = true)
	{ m_bShowGrid = bShow; }

	inline void ShowLabels( bool bShow = true)
	{ m_bShowMinMax = bShow; }


	CRect& getClientRect();


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(C2DPushGraph)
	//}}AFX_VIRTUAL

	// Generated message map functions
protected:
	//{{AFX_MSG(C2DPushGraph)
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnPaint();
	afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	//}}AFX_MSG

	static BOOL m_bRegistered;
	static BOOL RegisterClass();

	DECLARE_MESSAGE_MAP()

private:

	virtual void   internal_DrawGrid( CDC &dc, CRect &rect );
	virtual void   internal_DrawLines( CDC &dc, CRect &rect );
	virtual void   internal_DrawBar( CDC &dc, CRect &rect, 
	                                 PushGraphLine& rLine );
	virtual void   internal_DrawMinMax( CDC &dc, CRect& rect);

	CDC&           internal_InitBackBuffer( CPaintDC &dc );
	void           internal_FreeBackBuffer( CPaintDC &dc );
	PushGraphLine* internal_LineFromID( UINT uiLineID );
	
	
	/* Internal data members */


	COLORREF m_crTextColor;
	COLORREF m_crBGColor;
	COLORREF m_crGridColor;

	CString  m_strMaxLabel;
	CString  m_strMinLabel;

	bool   m_bShowMinMax;
	bool   m_bShowGrid;
	bool   m_bStylesModified;

	int    m_nMoveOffset;
	int    m_nMaxCoords;
	int    m_nMaxPeek;
	int    m_nMinPeek;
	int    m_nGridSize;
 	int    m_nPeekOffset;
	

	CBitmap  *m_pOldBitmap; // Original bitmap
	CBitmap  m_bmBack;      // Bitmap for backbuffering	
    CDC      m_dcBack;	

	unsigned short m_usLineInterval;
	CArray<PushGraphLine*, PushGraphLine*> m_aLines;

};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_2DPUSHGRAPH_H_INCLUDED)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -