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

📄 numberdisplay.cpp

📁 此程序实现了类似protel电路画图程序。
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// NumberDisplay.cpp: implementation of the NumberDisplay class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "pointtest.h"
#include "NumberDisplay.h"

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

#define FONTCOLOR RGB( 255,0,0 )
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

NumberDisplay::NumberDisplay()
{
	m_zhengNum = 0;
	CPoint point ;
	point.x = 1;
	LogPenText.lopnWidth = point;
	LogPenText.lopnStyle = PS_SOLID;
	LogPenText.lopnColor = RGB( 0,0,0 );
	LogPen8.lopnWidth = point;
	LogPen8.lopnStyle = PS_SOLID;
	LogPen8.lopnColor = RGB( 191,191,191 );
	LogPenBackground.lopnWidth = point;
	LogPenBackground.lopnStyle = PS_SOLID;
	LogPenBackground.lopnColor = RGB( 117,245,214 );
	m_Number = 0;          //保留小数位
	m_date = 0;            //将要显示得数 
	m_Hight = 0;           //窗口的宽和高
	m_Width = 0;
	m_LeftTopPoint = CPoint( 0,0 );     //窗口的左上角坐标
	m_HengWidth = 0;                    //横的宽和高
	m_HengHight = 0;
	m_ShuWidth = 0;                     //竖的宽和高
	m_ShuHight = 0;
	m_FontDistance = 0;                 //字体的间距
	m_FontToWindowDistance = 0;         //字体边到窗口边的距离
	m_BottomDistance = 0;               //字体底到窗口底的距离
	m_FontSum = 0;                      //字体的总个数 
	m_HengToShuDistance = 0;            //横和竖的间锯
	m_FontWidth = 0;                     //字体的宽和高
	m_FontHight = 0;

	m_Num = 0;
	m_tempPoint = CPoint( 0,0 );
	m_LFlag = FALSE;
	m_BeSelected = FALSE;

}

NumberDisplay::~NumberDisplay()
{

}

void NumberDisplay::SetParam( double date,CPoint point,int width,int hight,int i )
{
	m_Number = i;          //保留小数位
	m_date = date;
	m_LeftTopPoint = point;
	m_Width = width;
	m_Hight = hight;
	ArithPosition( date,width,hight );
}

void NumberDisplay::SetParam( double date,CPoint point,int width,int hight,int i,int j )
{
	m_zhengNum = j;     //整数位
	m_Number = i;          //保留小数位
	m_date = date;
	m_LeftTopPoint = point;
	m_Width = width;
	m_Hight = hight;
	ArithPosition( date,width,hight );
}

void NumberDisplay::ArithPosition( double date,int width,int hight )
{
	if ( hight<5||width<5 )
	{
		m_Flag = FALSE;              //不能显示标志
	}
	else
	{
		int i = 0;
		int sum;
		sum = int( date );
		if ( sum == 0 )
		{
			i = 1;
		}
		else
		{
			while ( sum )
			{
				sum = sum/10;
				i++;
			}
		}
	    if ( m_zhengNum == 0 )
		{
			if ( m_Number )
			{
				m_FontSum = i+m_Number+1;      //加1是因为有一个小数点
			}
			else
			{
				m_FontSum = i;
			}
		}
		else
		{
			if ( m_Number )
			{
				m_FontSum = m_zhengNum+m_Number+1;
			}
			else
			{
				m_FontSum = m_zhengNum;
			}
		}

		i = m_Width/m_FontSum;
		m_FontWidth = i/3*2;                  //字体的宽度
		m_FontToWindowDistance = i/3;         //字体到窗边的距离
		m_FontDistance = m_FontToWindowDistance;
		
		m_HengToShuDistance = m_FontWidth/20;  //横和竖的间距
		if ( m_HengToShuDistance == 0 )
		{
			m_HengToShuDistance = 1;
		}
		m_HengHight = m_FontWidth/8;           //横高
		m_HengWidth = m_FontWidth-m_HengToShuDistance*2;
		m_ShuWidth = m_HengHight;
		m_ShuHight = m_HengWidth*4/5;
		m_FontHight = m_ShuHight*2+2*m_HengToShuDistance;
		if ( m_FontHight<m_Hight )
		{
			m_BottomDistance = m_Hight/2-m_FontHight/2;
		}
		else
		{
			//m_FontHight = m_Hight/10*8;
			//m_ShuHight = m_FontHight/2-m
		}
	}
}



void NumberDisplay::Draw( CDC *pDC )
{
	CDC *dc = new CDC;
	CBitmap *bitmap = new CBitmap;
	CBitmap *old;
	dc->CreateCompatibleDC( pDC );
	bitmap->CreateCompatibleBitmap( pDC,m_Width,m_Hight );
	old = dc->SelectObject( bitmap );
	dc->PatBlt( 0,0,m_Width,m_Hight,WHITENESS );
	dc->FillSolidRect( 0,0,m_Width,m_Hight,LogPenBackground.lopnColor );
	int j = 1;
	int i = 0;
	int zheng,xiao;
	zheng = int( m_date );
	xiao = int( m_date*100 );
	xiao = xiao-zheng*100;
	int s = 0;
	if ( m_Number )
	{
		while ( s<m_Number )
		{
			i = xiao%10;
		    //array[j-1] = i;
			DrawNumber( i,dc,j );
			xiao =  xiao/10;
			j++;
			s++;
		}
		DrawPoint( j,dc );          //数字显示
		//DrawDoublePoint( j,dc );    //时间显示 
		j++;
	}
	if ( m_zhengNum == 0 )
	{
		if ( zheng == 0 )
		{
			DrawNumber( zheng,dc,j );
		}
		else
		{
			while ( zheng )
			{
				i = zheng%10;
				DrawNumber( i,dc,j );
				zheng = zheng/10;
				j++;
			}
		}
	}
	else
	{
		if ( zheng == 0 )
		{
			DrawNumber( zheng,dc,j );
			j++;
			DrawBottomPicture( dc,j );
			j++;
			DrawBottomPicture( dc,j );
			j++;
			DrawBottomPicture( dc,j );
		}
		else
		{
			s = 0;
			while ( zheng||s<4 )
			{
				if ( zheng == 0 )
				{
					DrawBottomPicture( dc,j );
				}
				else
				{
					i = zheng%10;
					DrawNumber( i,dc,j );
					zheng = zheng/10;
				}
				j++;
				s++;
			}
		}
	}

	pDC->BitBlt( m_LeftTopPoint.x,m_LeftTopPoint.y,m_Width,m_Hight,dc,0,0,SRCCOPY );
	dc->SelectObject( old );
	delete dc;
	delete bitmap;
}

void NumberDisplay::DrawNumber( int i,CDC *pDC,int j )
{
	switch ( i )
	{
	case 0:
		Draw0( pDC,j );
		break;
	case 1:
		Draw1( pDC,j );
		break;
	case 2:
		Draw2( pDC,j );
		break;
	case 3:
		Draw3( pDC,j );
		break;
	case 4:
		Draw4( pDC,j );
		break;
	case 5:
		Draw5( pDC,j );
		break;
	case 6:
		Draw6( pDC,j );
		break;
	case 7:
		Draw7( pDC,j );
		break;
	case 8:
		Draw8( pDC,j );
		break;
	case 9:
		Draw9( pDC,j );
		break;
	}
}

void NumberDisplay::Draw0( CDC *pDC,int j )
{
	DrawBottomPicture( pDC,j );
	CPoint point ;
	point.x = m_Width-m_FontToWindowDistance-j*m_FontWidth-(j-1 )*m_FontToWindowDistance/2;
	point.y = m_Hight-m_BottomDistance;
	DrawUpHeng( pDC,point,LogPenText );
	DrawLeftUpShu( pDC,point,LogPenText );
	DrawLeftDownShu( pDC,point,LogPenText );
	DrawRightUpShu( pDC,point,LogPenText );
	DrawRightDownShu( pDC,point,LogPenText );
	DrawDownHeng( pDC,point,LogPenText );
}

void NumberDisplay::Draw1( CDC *pDC,int j )
{
	DrawBottomPicture( pDC,j );
	CPoint point ;
	point.x = m_Width-m_FontToWindowDistance-j*m_FontWidth-(j-1 )*m_FontToWindowDistance/2;
	point.y = m_Hight-m_BottomDistance;
	DrawRightUpShu( pDC,point,LogPenText );
	DrawRightDownShu( pDC,point,LogPenText );
}

void NumberDisplay::Draw2( CDC *pDC,int j )
{
	DrawBottomPicture( pDC,j );
	CPoint point ;
	point.x = m_Width-m_FontToWindowDistance-j*m_FontWidth-(j-1 )*m_FontToWindowDistance/2;
	point.y = m_Hight-m_BottomDistance;
	DrawUpHeng( pDC,point,LogPenText );
	DrawMidHeng( pDC,point,LogPenText );
	DrawLeftDownShu( pDC,point,LogPenText );
	DrawRightUpShu( pDC,point,LogPenText );
	DrawDownHeng( pDC,point,LogPenText );
}

void NumberDisplay::Draw3( CDC *pDC,int j )
{
	DrawBottomPicture( pDC,j );
	CPoint point ;
	point.x = m_Width-m_FontToWindowDistance-j*m_FontWidth-(j-1 )*m_FontToWindowDistance/2;
	point.y = m_Hight-m_BottomDistance;
	DrawUpHeng( pDC,point,LogPenText );
	DrawMidHeng( pDC,point,LogPenText );
	DrawRightUpShu( pDC,point,LogPenText );
	DrawRightDownShu( pDC,point,LogPenText );
	DrawDownHeng( pDC,point,LogPenText );
}

void NumberDisplay::Draw4( CDC *pDC,int j )
{
	DrawBottomPicture( pDC,j );
	CPoint point ;
	point.x = m_Width-m_FontToWindowDistance-j*m_FontWidth-(j-1 )*m_FontToWindowDistance/2;
	point.y = m_Hight-m_BottomDistance;
	DrawMidHeng( pDC,point,LogPenText );
	DrawLeftUpShu( pDC,point,LogPenText );
	DrawRightUpShu( pDC,point,LogPenText );
	DrawRightDownShu( pDC,point,LogPenText );
}

void NumberDisplay::Draw5( CDC *pDC,int j )
{
	DrawBottomPicture( pDC,j );
	CPoint point ;
	point.x = m_Width-m_FontToWindowDistance-j*m_FontWidth-(j-1 )*m_FontToWindowDistance/2;

⌨️ 快捷键说明

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