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

📄 cdrawlineargauges.cpp

📁 一个标尺控件
💻 CPP
字号:
// DrawLinearGauges.cpp: implementation of the CDrawLinearGauges class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CELinearGauge.h"
#include "CDrawLinearGauges.h"

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

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

CDrawLinearGauges::CDrawLinearGauges()
{
	m_row=0;
	m_col=0;
	m_bkColor=RGB(255,255,255);
	m_arrayCellLinearGauge.SetSize(0);
}

CDrawLinearGauges::~CDrawLinearGauges()
{

}

void CDrawLinearGauges::SetGrid(long row,long col)
{	
	if(row <= 0 || col <=0)
	{
		return;
	}

	m_row = row;
	m_col = col;
	m_arrayCellLinearGauge.SetSize(row*col);

	RECT rect;
	rect = m_rect;
	long index=0;
	long height = (m_rect.bottom - m_rect.top) / m_row;
	long width = (m_rect.right - m_rect.left) / m_col;

	for (long lrow = 0 ; lrow < m_row ; lrow++)
	{
		for (long lcol = 0 ; lcol < m_col ;lcol++)
		{
			rect.top=rect.top+height*lrow;
			rect.left=rect.left+width*lcol;
			rect.bottom  = rect.top+height;
			rect.right = rect.left+width;
			
			rect.top=rect.top+10;
			rect.left=rect.left+10;
			rect.bottom  = rect.bottom-10;
			rect.right = rect.right-10;

			m_arrayCellLinearGauge[index].SetRect(rect);
			index++;
			//DrawRect(pDC,m_arrayCell[index].m_rect);
			rect.top=m_rect.top;
			rect.left=m_rect.left;
		}
	}
}

void CDrawLinearGauges::Draw(HDC hDC)
{
	/*RECT rect = m_rect;
	m_hbrush = CreateSolidBrush(m_bkColor);
	FillRect(hDC, &rect,m_hbrush);
	DeleteObject (m_hbrush) ;*/


	for(long l =0;l<m_arrayCellLinearGauge.GetSize();l++)
	{
		m_arrayCellLinearGauge[l].Draw(hDC);
	}
}


POINT CDrawLinearGauges::SetPoint(POINT pt)
{
	POINT ptTemp;
	CString str;
	for(long l =0;l<m_arrayCellLinearGauge.GetSize();l++)
	{
		RECT rc;
		m_arrayCellLinearGauge[l].GetRect(&rc); 
		if(PtInRect(&rc,pt))
		{
			//CDrawLinearGauges[l].m_active=1;
			//m_strOut=m_strOut+m_arrayCell[l].m_value;

			ptTemp.x = (l / m_col) ;//+ 1;
			ptTemp.y = (l % m_col) ;//+ 1;
			return ptTemp;
		}
	}
	ptTemp.x = 0;
	ptTemp.y = 0;
	return ptTemp;
	
}

⌨️ 快捷键说明

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