windows ce开发技巧与实例光盘代码

源代码在线查看: bar.cpp

软件大小: 21560 K
上传用户: cong328
关键词: windows 开发技巧 光盘 代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				// Bar.cpp: implementation of the CBar class.
				//
				//////////////////////////////////////////////////////////////////////
				
				#include "stdafx.h"
				#include "Bar.h"
				
				#ifdef _DEBUG
				#undef THIS_FILE
				static char THIS_FILE[]=__FILE__;
				#define new DEBUG_NEW
				#endif
				
				//////////////////////////////////////////////////////////////////////
				// Construction/Destruction
				//////////////////////////////////////////////////////////////////////
				
				CBar::CBar()
				{
					CoordinateDirection = VER;
					XFieldMode = ON;
					LegendMode = BOTTOM;
					TitleMode = TOP;
					GraphMode = FALSE;
					WithDash = FALSE;
					Column = FALSE;
				
					yDeta = 5;
					yCoorDeta = 0;
				}
				
				CBar::~CBar()
				{
				
				}
				void CBar::DrawCoordinate(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy,BOOL WithDash)
				{
					if(GraphMode == FALSE)//Flat
						Draw2DCoordinate(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy,WithDash);
					else
						Draw3DCoordinate(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy,WithDash);
				}
				void CBar::Draw2DCoordinate(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy,BOOL WithDash)
				{
					int nDeta = 5;
					int nCount = (YMax - YMin)/nDeta ;
					int nCoorDeta = (RightBottomy - LeftTopy)/nCount;
					yCoorDeta = nCoorDeta;
					while(nCoorDeta < 10 )
					{
						yDeta = nDeta;
						nDeta += 5;
						nCount = (YMax - YMin)/nDeta ;
						nCoorDeta = (RightBottomy - LeftTopy)/nCount;
						yCoorDeta = nCoorDeta;
					}
					DrawLine(pDC,LeftTopx,LeftTopy,LeftTopx,RightBottomy);
					DrawLine(pDC,LeftTopx,RightBottomy,RightBottomx,RightBottomy);
					if(WithDash)
					{
						DrawLine(pDC,RightBottomx,RightBottomy,RightBottomx,LeftTopy);
						DrawLine(pDC,RightBottomx,LeftTopy,LeftTopx,LeftTopy);
					}
					CString CoordinateValue;
					CoordinateValue.Format(_T("%3d"),YMin);
					DrawYCoordinateValue(pDC,LeftTopx-18,RightBottomy-5,CoordinateValue);
					for(int i=1;i					{
						if(WithDash)
							DrawDashLine(pDC,LeftTopx,RightBottomy-nCoorDeta*i,RightBottomx,RightBottomy-nCoorDeta*i);
						DrawLine(pDC,LeftTopx,RightBottomy-nCoorDeta*i,LeftTopx+5,RightBottomy-nCoorDeta*i);
						CoordinateValue.Format(_T("%3d"),YMin+nDeta*i);
						DrawYCoordinateValue(pDC,LeftTopx-18,RightBottomy-nCoorDeta*i-5,CoordinateValue);
					}
				
					DrawXName(pDC,RightBottomx-12*XName.GetLength(),RightBottomy+15,XName);
					DrawYName(pDC,LeftTopx-35,LeftTopy+12*YName.GetLength(),YName);
					DrawTitle(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy,TitleMode);
				}
				void CBar::Draw3DCoordinate(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy,BOOL WithDash)
				{
					int nXDeta = (RightBottomx-LeftTopx)/(m_Legend.GetSize()+1);
					if(Column == FALSE)
					{
						int nDeta = 5;
						int nCount = (YMax - YMin)/nDeta ;
						int nCoorDeta = (RightBottomy - LeftTopy)/nCount;
						yCoorDeta = nCoorDeta;
						while(nCoorDeta < 10 )
						{
							nDeta += 5;
							yDeta = nDeta;
							nCount = (YMax - YMin)/nDeta ;
							nCoorDeta = (RightBottomy - LeftTopy)/nCount;
							yCoorDeta = nCoorDeta;
						}
						DrawLine(pDC,LeftTopx,LeftTopy,LeftTopx,RightBottomy);
						DrawLine(pDC,LeftTopx,RightBottomy,RightBottomx,RightBottomy);
						DrawLine(pDC,LeftTopx,LeftTopy,LeftTopx+nXDeta/2,LeftTopy-nXDeta/2);
						DrawLine(pDC,LeftTopx,RightBottomy,LeftTopx+nXDeta/2,RightBottomy-nXDeta/2);
						DrawLine(pDC,RightBottomx,RightBottomy,RightBottomx+nXDeta/2,RightBottomy-nXDeta/2);
						DrawLine(pDC,LeftTopx+nXDeta/2,LeftTopy-nXDeta/2,LeftTopx+nXDeta/2,RightBottomy-nXDeta/2);
						DrawLine(pDC,RightBottomx+nXDeta/2,LeftTopy-nXDeta/2,RightBottomx+nXDeta/2,RightBottomy-nXDeta/2);
						DrawLine(pDC,LeftTopx+nXDeta/2,LeftTopy-nXDeta/2,RightBottomx+nXDeta/2,LeftTopy-nXDeta/2);
						DrawLine(pDC,LeftTopx+nXDeta/2,RightBottomy-nXDeta/2,RightBottomx+nXDeta/2,RightBottomy-nXDeta/2);
				
						CString CoordinateValue;
						CoordinateValue.Format(_T("%3d"),YMin);
						DrawYCoordinateValue(pDC,LeftTopx-18,RightBottomy-5,CoordinateValue);
						for(int i=1;i						{
							if(WithDash)
							{
								DrawDashLine(pDC,LeftTopx,RightBottomy-nCoorDeta*i,LeftTopx+nXDeta/2,RightBottomy-nCoorDeta*i-nXDeta/2);
								DrawDashLine(pDC,LeftTopx+nXDeta/2,RightBottomy-nCoorDeta*i-nXDeta/2,RightBottomx+nXDeta/2,RightBottomy-nCoorDeta*i-nXDeta/2);
							}
							CoordinateValue.Format(_T("%3d"),YMin+nDeta*i);
							DrawYCoordinateValue(pDC,LeftTopx-18,RightBottomy-nCoorDeta*i-5,CoordinateValue);
						}
						
						DrawXName(pDC,RightBottomx-12*XName.GetLength(),RightBottomy+15,XName);
						DrawYName(pDC,LeftTopx-35,LeftTopy+12*YName.GetLength(),YName);
						DrawTitle(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy,TitleMode);
					}
					else
					{
						Draw2DCoordinate(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy,WithDash);
					}
				}
				void CBar::DrawBar(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy)
				{
					int nWidth = 30;
					DrawCoordinate(pDC,LeftTopx+40,LeftTopy+37,RightBottomx-4-nWidth,RightBottomy-54,WithDash);
					DrawContent(pDC,LeftTopx+40,LeftTopy+37,RightBottomx-4-nWidth,RightBottomy-54);
					DrawLegend(pDC,RightBottomx-2-nWidth,LeftTopy+37,nWidth,LegendMode);
				}
				void CBar::DrawContent(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy)
				{
					if(GraphMode == FALSE)
						Draw2DBar(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy);
					else
						Draw3DBar(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy);
				}
				void CBar::Draw2DBarContent(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy)
				{
					int nXDeta = (RightBottomx-LeftTopx)/(m_Legend.GetSize()+1);
					for(int i=1;i					{
						if(m_Legend.GetAt(i-1).Value > YMax)
						{
							Legend LegendTmp = m_Legend.GetAt(i-1); 
							LegendTmp.Value = YMax;
							m_Legend.SetAt(i-1,LegendTmp);
						}
						if(m_Legend.GetAt(i-1).Value < YMin) 
						{
							Legend LegendTmp = m_Legend.GetAt(i-1); 
							LegendTmp.Value = YMin;
							m_Legend.SetAt(i-1,LegendTmp);
						}
						if(WithDash)
							DrawDashLine(pDC,LeftTopx+nXDeta*i,RightBottomy,LeftTopx+nXDeta*i,LeftTopy);
						int Height = ((int)(m_Legend.GetAt(i-1).Value+0.5)-YMin)*yCoorDeta/yDeta;
					//	Height = (Height						if(GraphMode == FALSE)
							DrawRectangle(pDC,LeftTopx+nXDeta*i-nXDeta/2+1,RightBottomy-Height,LeftTopx+nXDeta*i+nXDeta/2-1,RightBottomy,m_Legend.GetAt(i-1).Graph.LineSize,m_Legend.GetAt(i-1).Graph.LineColor,m_Legend.GetAt(i-1).Graph.FillColor);
						else
						{
							DrawColumn(pDC,LeftTopx+nXDeta*i-nXDeta/2+1,RightBottomy-nXDeta/2+2-Height,LeftTopx+nXDeta*i+nXDeta/2-1,RightBottomy+nXDeta/2-2-Height,Height,m_Legend.GetAt(i-1).Graph.LineSize,m_Legend.GetAt(i-1).Graph.LineColor,m_Legend.GetAt(i-1).Graph.FillColor);
						//	DrawColumn(pDC,80,80,80+40,80+30,Height,m_Legend.GetAt(i-1).Graph.LineSize,m_Legend.GetAt(i-1).Graph.LineColor,m_Legend.GetAt(i-1).Graph.FillColor);
						}
						switch(XFieldMode)
						{
						case LEFT:
						case RIGHT:
						case NONE:
							break;
						case TOP:
						//	if(nXDeta < 12*m_Legend.GetAt(i-1).Name.GetLength())
						//		DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-Height-1,m_Legend.GetAt(i-1).Name,HOR);
						//	else
								DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-Height-15,m_Legend.GetAt(i-1).Name);
							break;
						case BOTTOM:
							DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy+15,m_Legend.GetAt(i-1).Name);
							break;
						case ON:
							//if(nXDeta < 12*m_Legend.GetAt(i-1).Name.GetLength())
							DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-5,m_Legend.GetAt(i-1).Name,HOR);
							//else
							//	DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-5,m_Legend.GetAt(i-1).Name);
							break;
						}
					}
				}
				void CBar::Draw3DBarContent(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy)
				{
					if(Column == FALSE)
					{
						int nXDeta = (RightBottomx-LeftTopx)/(m_Legend.GetSize()+1);
						for(int i=1;i						{
							if(m_Legend.GetAt(i-1).Value > YMax)
							{
								Legend LegendTmp = m_Legend.GetAt(i-1); 
								LegendTmp.Value = YMax;
								m_Legend.SetAt(i-1,LegendTmp);
							}
							if(m_Legend.GetAt(i-1).Value < YMin) 
							{
								Legend LegendTmp = m_Legend.GetAt(i-1); 
								LegendTmp.Value = YMin;
								m_Legend.SetAt(i-1,LegendTmp);
							}
				
							int Height = ((int)(m_Legend.GetAt(i-1).Value+0.5)-YMin)*yCoorDeta/yDeta;
							//	Height = (Height							DrawCub(pDC,LeftTopx+nXDeta*i-nXDeta/2+1,RightBottomy-Height,LeftTopx+nXDeta*i+nXDeta/2-1,RightBottomy-Height,Height,m_Legend.GetAt(i-1).Graph.LineSize,m_Legend.GetAt(i-1).Graph.LineColor,m_Legend.GetAt(i-1).Graph.FillColor);
							
							switch(XFieldMode)
							{
							case LEFT:
							case RIGHT:
							case NONE:
								break;
							case TOP:
								//	if(nXDeta < 12*m_Legend.GetAt(i-1).Name.GetLength())
								//		DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-Height-1,m_Legend.GetAt(i-1).Name,HOR);
								//	else
								DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-Height-15,m_Legend.GetAt(i-1).Name);
								break;
							case BOTTOM:
								DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy+15,m_Legend.GetAt(i-1).Name);
								break;
							case ON:
								//if(nXDeta < 12*m_Legend.GetAt(i-1).Name.GetLength())
								DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-5,m_Legend.GetAt(i-1).Name,HOR);
								//else
								//	DrawXCoordinateValue(pDC,LeftTopx+nXDeta*i-nXDeta/2+2,RightBottomy-5,m_Legend.GetAt(i-1).Name);
								break;
							}
						}
					}
					else
					{
						Draw2DBarContent(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy);
					}
				}
				void CBar::Draw2DBar(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy)
				{
					Draw2DCoordinate(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy,WithDash);
					Draw2DBarContent(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy);
				}
				void CBar::Draw3DBar(CDC* pDC,int LeftTopx,int LeftTopy,int RightBottomx,int RightBottomy)
				{
					Draw3DCoordinate(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy,WithDash);
					Draw3DBarContent(pDC,LeftTopx,LeftTopy,RightBottomx,RightBottomy);
				}			

相关资源