chartgrid.cpp

来自「BCB CHART控件 在Wince5.0下的移植」· C++ 代码 · 共 106 行

CPP
106
字号
/*
 *
 *	ChartGrid.cpp
 *
 *	Written by C閐ric Moonen (cedric_moonen@hotmail.com)
 *
 *
 *
 *	This code may be used for any non-commercial and commercial purposes in a compiled form.
 *	The code may be redistributed as long as it remains unmodified and providing that the 
 *	author name and this disclaimer remain intact. The sources can be modified WITH the author 
 *	consent only.
 *	
 *	This code is provided without any garanties. I cannot be held responsible for the damage or
 *	the loss of time it causes. Use it at your own risks
 *
 *	An e-mail to notify me that you are using this code is appreciated also.
 *
 *
 */

#include "stdafx.h"
#include "ChartGrid.h"
#include "ChartAxis.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CChartGrid::CChartGrid(CChartCtrl* pParent, CChartAxis* pAxis, bool bHoriz) : CChartObject(pParent)
{
	m_iTickCount = 0;
	m_bIsHorizontal = bHoriz;
	m_pParentAxis = pAxis;

	SetColor(RGB(128,128,128));
}

CChartGrid::~CChartGrid()
{

}

void CChartGrid::Draw(CDC *pDC)
{
	if (!m_bIsVisible)
		return;

	if (!pDC->GetSafeHdc() )
		return;

	CPen* pOldPen;
	CPen NewPen(PS_SOLID,0,m_ObjectColor);

	pOldPen = pDC->SelectObject(&NewPen);

	int ActuPosition = 0;
	for (int i=0;i<=m_iTickCount;i++)
	{
		ActuPosition = (int)m_pParentAxis->GetTickScreenPos(i);
		if (!m_bIsHorizontal)
		{
			int ActuX = m_ObjectRect.left;

			while (true)
			{
				if (!Clip(ActuX,ActuPosition))
					break;
				pDC->MoveTo(ActuX,ActuPosition);

				ActuX += 3;
				Clip(ActuX,ActuPosition);
				pDC->LineTo(ActuX,ActuPosition);

				ActuX += 3;
			}
		}
		else
		{
			int ActuY = m_ObjectRect.bottom;

			while (true)
			{
				if (!Clip(ActuPosition,ActuY))
					break;
				pDC->MoveTo(ActuPosition,ActuY);

				ActuY -= 3;
				Clip(ActuPosition,ActuY);
				pDC->LineTo(ActuPosition,ActuY);

				ActuY -= 3;
			}
		}

	}

	pDC->SelectObject(pOldPen);
}

⌨️ 快捷键说明

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