Click here to Skip to main content
15,885,648 members
Articles / Desktop Programming / MFC

2D Graph ActiveX Control

Rate me:
Please Sign up or sign in to vote.
4.89/5 (159 votes)
5 Aug 2003MIT8 min read 1.5M   70.2K   339  
An ActiveX control for 2D data visualisation
#if !defined(AFX_NTGRAPHCTL_H__4E772943_A5F2_4917_B53F_DE7BE01A6E36__INCLUDED_)
#define AFX_NTGRAPHCTL_H__4E772943_A5F2_4917_B53F_DE7BE01A6E36__INCLUDED_

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

#ifndef MAX
#define MAX 1
#endif

#ifndef MIN
#define MIN 0
#endif

#define MAX_ELEMENTS 100

class CGraphElement {

public :
	CGraphElement() ;
	BOOL bIsPlotAvailable ;
	double *dValueX ;
	double *dValueY ;
	COLORREF m_plotColor ;
	BOOL AllocElement(UINT nPoint);
	BOOL FreeElement();

protected:
	BOOL bBufferAllocated;
} ;

// NTGraphCtl.h : Declaration of the CNTGraphCtrl ActiveX Control class.

/////////////////////////////////////////////////////////////////////////////
// CNTGraphCtrl : See NTGraphCtl.cpp for implementation.

class CNTGraphCtrl : public COleControl
{
	DECLARE_DYNCREATE(CNTGraphCtrl)

// Constructor
public:
	CNTGraphCtrl();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CNTGraphCtrl)
	public:
	virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual void DoPropExchange(CPropExchange* pPX);
	virtual void OnResetState();
	virtual DWORD GetControlFlags();
	//}}AFX_VIRTUAL

// Implementation
protected:
	~CNTGraphCtrl();

	DECLARE_OLECREATE_EX(CNTGraphCtrl)    // Class factory and guid
	DECLARE_OLETYPELIB(CNTGraphCtrl)      // GetTypeInfo
	DECLARE_PROPPAGEIDS(CNTGraphCtrl)     // Property page IDs
	DECLARE_OLECTLTYPE(CNTGraphCtrl)	  // Type name and misc status

	// Subclassed control support
	BOOL IsSubclassedControl();
	LRESULT OnOcmCommand(WPARAM wParam, LPARAM lParam);

// Message maps
	//{{AFX_MSG(CNTGraphCtrl)
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

// Dispatch maps
	//{{AFX_DISPATCH(CNTGraphCtrl)
	BOOL m_showGrid;
	afx_msg void OnShowGridChanged();
	BOOL m_changeMappingMode;
	afx_msg void OnChangeMappingModeChanged();
	CString m_strLabelX;
	afx_msg void OnXLabelChanged();
	CString m_strLabelY;
	afx_msg void OnYLabelChanged();
	OLE_COLOR m_gridColor;
	afx_msg void OnGridColorChanged();
	OLE_COLOR m_labelColor;
	afx_msg void OnLabelColorChanged();
	OLE_COLOR m_axisColor;
	afx_msg void OnAxisColorChanged();
	short m_nGridX;
	afx_msg void OnNGridXChanged();
	short m_nGridY;
	afx_msg void OnNGridYChanged();
	double m_minX;
	afx_msg void OnMinXChanged();
	double m_maxX;
	afx_msg void OnMaxXChanged();
	double m_minY;
	afx_msg void OnMinYChanged();
	double m_maxY;
	afx_msg void OnMaxYChanged();
	BOOL m_showCursor;
	afx_msg void OnShowCursorChanged();
	CString m_strGraphTitle;
	afx_msg void OnGraphTitleChanged();
	OLE_COLOR m_cursorColor;
	afx_msg void OnCursorColorChanged();
	afx_msg OLE_COLOR GetPlotColor();
	afx_msg void SetPlotColor(OLE_COLOR nNewValue);
	afx_msg short GetElement();
	afx_msg void SetElement(short nNewValue);
	afx_msg short GetElementCount();
	afx_msg void SetElementCount(short nNewValue);
	afx_msg void ClearGraph();
	afx_msg BOOL CreateElement(long nElement);
	afx_msg BOOL SetRange(double MinX, double MaxX,double MinY,double MaxY);
	afx_msg BOOL SetXYValue(double x, double y, long index, short iElementId);
	//}}AFX_DISPATCH
	DECLARE_DISPATCH_MAP()

	afx_msg void AboutBox();

// Event maps
	//{{AFX_EVENT(CNTGraphCtrl)
	//}}AFX_EVENT
	DECLARE_EVENT_MAP()


// Dispatch and event IDs
public:
	enum {
	//{{AFX_DISP_ID(CNTGraphCtrl)
	dispidShowGrid = 1L,
	dispidChangeMappingMode = 2L,
	dispidXLabel = 3L,
	dispidYLabel = 4L,
	dispidGridColor = 5L,
	dispidLabelColor = 6L,
	dispidAxisColor = 7L,
	dispidNGridX = 8L,
	dispidNGridY = 9L,
	dispidMinX = 10L,
	dispidMaxX = 11L,
	dispidMinY = 12L,
	dispidMaxY = 13L,
	dispidPlotColor = 17L,
	dispidElement = 18L,
	dispidElementCount = 19L,
	dispidShowCursor = 14L,
	dispidGraphTitle = 15L,
	dispidCursorColor = 16L,
	dispidClearGraph = 20L,
	dispidCreateElement = 21L,
	dispidSetRange = 22L,
	dispidSetXYValue = 23L,
	//}}AFX_DISP_ID
	};

	CPoint Corrdinate(double x, double y);
	CGraphElement mpElement[MAX_ELEMENTS] ;
	int nElementCount ;
	COLORREF m_BGColor ;
	BOOL bFontIsCreate ;


protected:
	BOOL m_bIsCursorInRange;
	void DrawCursor();
	double m_dXCur;
	double m_dYCur;
	short m_ElementId;
	void ResCalc();
	void CalcRect();
	void CreateFont();
	void DrawGraphTitle();
	void DrawGrid();
	void DrawAxis();
	void DrawTicks();
	void DrawAxisLabel();
	void PlotElement();



	int nPointCount ;
	int nPlotIndex ;
	double dResY, dResX ;
	double dRangeY[2], dRangeX[2];


	BOOL bIsElementAllocated ;

private:
 CRect m_ctlRect,m_clientRect, m_axisRect;
 CDC* m_pDC;

 	CFont *pTickFont ;
	CFont *pTitleFont;
	CFont *pXLabelFont;
	CFont *pYLabelFont;

 //Function to Intialize DC and mapping mode
 void PrepareForDrawing(CRect rect); 


};

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

#endif // !defined(AFX_NTGRAPHCTL_H__4E772943_A5F2_4917_B53F_DE7BE01A6E36__INCLUDED)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions