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

📄 view1.cpp

📁 《面向对象程序设计实用教程》一书的源码
💻 CPP
字号:
// View1.cpp : implementation file
//

#include "stdafx.h"
#include "cge.h"
#include "View1.h"

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

/////////////////////////////////////////////////////////////////////////////
// CView1

IMPLEMENT_DYNCREATE(CView1, CView)

CView1::CView1()
{	
}

CView1::~CView1()
{
}


BEGIN_MESSAGE_MAP(CView1, CView)
	//{{AFX_MSG_MAP(CView1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CView1 drawing

void CView1::OnDraw(CDC* pDC)
{
	CCgeDoc* pDoc = (CCgeDoc* )GetDocument();
	CString string;
	CRect rect;
	GetClientRect(&rect);
	int i_temp;
	float f_temp;
	//float n = pDoc->Num_Pointes * pDoc->m_stepX/rect.Width();
	
	for(int i = rect.left;i<rect.right;i+=10)
	{
	    if(((i-rect.left)%50) == 0)
		{
			pDC->MoveTo(i, rect.bottom-8);
			pDC->LineTo(i, rect.bottom);
			if(!pDoc->m_CMyLineList.IsEmpty() && ((i-rect.left)%100 == 0))
			{			
				//string.Format("%d", int((i+pDoc->m_ViewLeft)/10/pDoc->m_stepX));
				//string.Format("%d", int((i+pDoc->m_ViewLeft)* pDoc->m_jiange/pDoc->m_stepX));
				//string.Format("%d", int(((i+pDoc->m_ViewLeft)* pDoc->m_jiange)/pDoc->m_stepX));
				f_temp = (i+pDoc->m_ViewLeft)* pDoc->m_jiange;
				i_temp = f_temp/pDoc->m_stepX;
				string.Format("%d", i_temp);
				//if(pDoc->m_jiange == 0.0250000)
				if(int(pDoc->m_jiange*1000)==25)
				{
					if(i_temp%5==0) pDC->TextOut(i+1, rect.bottom-20, string);
				}else
				{
					//string.Format("%d", i_temp);
					pDC->TextOut(i+1, rect.bottom-20, string);
				}
				//pDC->TextOut(i+1, rect.bottom-20, string);
			}
		}
		else 
		{
			pDC->MoveTo(i, rect.bottom-3);
			pDC->LineTo(i, rect.bottom);
		}
	}

	//	  DrawS_Scale(pDC,pDoc);
	  /*
	  int d= pDoc->HPos;	  
	  // 将变化的部分从位图拷贝到屏幕上
	   rect.left = 0 + d;
	   rect.top = 0;
	   rect.right = m_nMaxX;
	   rect.bottom = m_nMaxY;       
	   pDC->BitBlt( 0,0,//rect.left, rect.top,
		1024,20,  //取目的图和原图的宽和高(一样)
		//rect.Width(), rect.Height(),		
		&m_MemDC,  //原设备的描述表
		d, 0,  //取原图的起点(宽和高同目的图一样)
		//rect.left, rect.top,
		SRCCOPY );	  
	  */
/*
	  char ds[10];
	  pDoc->m_x = pDoc->Num_Pointes;
	  itoa(	pDoc->Num_Pointes,ds,10);
	  pDC->TextOut(20,5,ds);

	  itoa(	pDoc->m_jiange,ds,10);
	  pDC->TextOut(70,5,ds);
*/
	  //RedrawWindow(NULL,NULL);
}

/////////////////////////////////////////////////////////////////////////////
// CView1 diagnostics

#ifdef _DEBUG
void CView1::AssertValid() const
{
	CView::AssertValid();
}

void CView1::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CView1 message handlers
/*
void CView1::DrawScale(CDC *pDC, CCgeDoc *pDoc)//画刻度尺
{
	 CPen* pOldPen;
	 CPen NewPen;
	 int i;		 
     NewPen.CreatePen(PS_SOLID,1,RGB(0,0,0)); 
	 pOldPen = pDC->SelectObject(&NewPen);
	 pDC->SetBkColor (RGB(255,255,255));
	 i = 0;
	 int m_kdgs,Lt;
	 float Lx;
	 CString Ls,Ls2;
	 Lt = pDoc->Num_Pointes;// * pDoc->m_stepX;
	 Ls.Format("%d",Lt);
	 Ls2 = Ls.Left(2);
	 m_kdgs = atoi(Ls2) + 1;
	 RECT rect;
	 GetClientRect(&rect);
	 
	 Lx = pDoc->Num_Pointes * pDoc->m_stepX / (m_kdgs - 1);/// ??????????????
	
	 do
	 {
		 int f=i;
		 f= (int(f/10))*10;
		 if ( i == f)
		 {
			 Ls.Format("%d",i); //注意数据类型
			 //pDC->TextOut(pDoc->m_viewX0 + i*Lx + 1,5,Ls);  // draw "0,1,2..."	
			 pDC->MoveTo(pDoc->m_viewX0 + i*Lx,0);
			 pDC->LineTo(pDoc->m_viewX0 + i*Lx,10);   //  draw "|"   
		 }else
		 {
			 pDC->MoveTo(pDoc->m_viewX0 + i*Lx,0);
			 pDC->LineTo(pDoc->m_viewX0 + i*Lx,3);   //  draw "|"   
		 }
//		 pDC->TextOut(pDoc->m_viewX0 + i*Lx + 1,5,Ls);  // draw "0,1,2..."	
		 i ++;//= 100;
 	 }while(i < m_kdgs);  //设为最大

	 	    
	 pDC->SelectObject(pOldPen);
     //pDC->SetBkColor (m_TextBkCr);
	 
}

int CView1::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
    CCgeDoc* pDoc = (CCgeDoc* )GetDocument();	
	CDC* pDC = GetDC();
	CBitmap  m_Bitmap;
    HBRUSH m_hBrush;      
	
    m_nMaxX = 20480;
	//m_nMaxX = pDoc->Num_Pointes;//GetSystemMetrics(SM_CXSCREEN);
	m_nMaxY = 20;//GetSystemMetrics(SM_CYSCREEN);	
	
	//创建显示DC的兼容内存DC
    m_MemDC.CreateCompatibleDC(pDC);
	// 创建显示内存位图
	m_Bitmap.CreateCompatibleBitmap( pDC,
								m_nMaxX,
								m_nMaxY );
	// 将设备和位图产生关联
	CBitmap* pOldBitmap = m_MemDC.SelectObject( &m_Bitmap );

	//设色为白色
    m_hBrush = (HBRUSH) GetStockObject(WHITE_BRUSH);
	SelectObject(m_MemDC,m_hBrush);
	PatBlt(m_MemDC,0,0,m_nMaxX,m_nMaxY,PATCOPY);

	//直写位图到内存
	DrawScale(&m_MemDC,pDoc);  
   
       	
	return 0;
}

void CView1::DrawS_Scale(CDC *pDC, CCgeDoc *pDoc)
{
     CPen* pOldPen;
	 CPen NewPen;
	 int i,j;		 
     NewPen.CreatePen(PS_SOLID,1,RGB(0,0,0)); 
	 pOldPen = pDC->SelectObject(&NewPen);
	 pDC->SetBkColor (RGB(255,255,255));
	 i = 0;
	 int m_kdgs, Lt;
	 //int full_timelabel;	 
	 
	 CString Ls,Ls2;
	 
	 m_kdgs = atoi(Ls2) + 1;
	 RECT rect;
	 GetClientRect(&rect);
	 
	 Lt = rect.right / pDoc->m_TimelabelStep;//pDoc->Num_Pointes;// * pDoc->m_stepX;
	 Ls.Format("%d",Lt);
	 Ls2 = Ls.Left(2); 
	 m_kdgs = atoi(Ls2) + 1;
	 pDoc->full_timelabel = float(pDoc->Num_Pointes * pDoc->m_jiange) / rect.right ;  //  /m_kdgs) ;		
	 for(i=0;i<m_kdgs;i++)
	 {	 
			 pDC->MoveTo( pDoc->m_viewX0 + i* pDoc->m_TimelabelStep, rect.bottom - 7 );
			 pDC->LineTo( pDoc->m_viewX0 + i* pDoc->m_TimelabelStep, rect.bottom );   //  draw "|"   			 
			 if(!pDoc->m_CMyLineList.IsEmpty() && (i%2==0) )
			 {
				if(pDoc->fullScreen)		//满屏刻度调整
				{
					Lt = i * pDoc->full_timelabel * pDoc->m_TimelabelStep; //满屏刻度调整 50					
				}
				else
				{
					Lt = (pDoc->HPos + i * pDoc->m_TimelabelStep - pDoc->m_viewX0 )
										* pDoc->m_jiange * pDoc->Num_FScishu ;  
				}
				if(pDoc->s[4].Right(2) == "us")
				{
					Lt = Lt / 1000;
				}
				Ls.Format("%d", Lt);
				pDC->TextOut(pDoc->m_viewX0 + i*pDoc->m_TimelabelStep + 1, rect.top, Ls);
			 }
			 for(j=0;j<5;j++)
			 {
				pDC->MoveTo( pDoc->m_viewX0 + i*50 + j*10, rect.bottom - 2 );//-3
				pDC->LineTo( pDoc->m_viewX0 + i*50 + j*10, rect.bottom );   //  draw "|"   
			 }				 
		 
 	 }
	 	    
	 pDC->SelectObject(pOldPen);
     //pDC->SetBkColor (m_TextBkCr);
	 

}
*/

⌨️ 快捷键说明

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