www.pudn.com > AnimateLine1.rar > AnimateLine1View.cpp


// AnimateLine1View.cpp : implementation of the CAnimateLine1View class 
// 
 
#include "stdafx.h" 
#include "AnimateLine1.h" 
 
#include "AnimateLine1Doc.h" 
#include "AnimateLine1View.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CAnimateLine1View 
 
IMPLEMENT_DYNCREATE(CAnimateLine1View, CFormView) 
 
BEGIN_MESSAGE_MAP(CAnimateLine1View, CFormView) 
	//{{AFX_MSG_MAP(CAnimateLine1View) 
	ON_WM_TIMER() 
	//}}AFX_MSG_MAP 
	// Standard printing commands 
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CAnimateLine1View construction/destruction 
 
CAnimateLine1View::CAnimateLine1View() 
	: CFormView(CAnimateLine1View::IDD) 
{ 
	//{{AFX_DATA_INIT(CAnimateLine1View) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
	// TODO: add construction code here 
 
} 
 
CAnimateLine1View::~CAnimateLine1View() 
{ 
} 
 
void CAnimateLine1View::DoDataExchange(CDataExchange* pDX) 
{ 
	CFormView::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CAnimateLine1View) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
BOOL CAnimateLine1View::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CFormView::PreCreateWindow(cs); 
} 
 
void CAnimateLine1View::OnInitialUpdate() 
{ 
	CFormView::OnInitialUpdate(); 
	GetParentFrame()->RecalcLayout(); 
	ResizeParentToFit(); 
 
/////////////////////我的代码/////////////////// 
	//以下代码意味着:曲线每隔200毫秒前进5单元水平距离 
    offsetx=5; 
    SetTimer(1,200,NULL); 
/////////////////////我的代码/////////////////// 
 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAnimateLine1View printing 
 
BOOL CAnimateLine1View::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CAnimateLine1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CAnimateLine1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
void CAnimateLine1View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add customized printing code here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAnimateLine1View diagnostics 
 
#ifdef _DEBUG 
void CAnimateLine1View::AssertValid() const 
{ 
	CFormView::AssertValid(); 
} 
 
void CAnimateLine1View::Dump(CDumpContext& dc) const 
{ 
	CFormView::Dump(dc); 
} 
 
CAnimateLine1Doc* CAnimateLine1View::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimateLine1Doc))); 
	return (CAnimateLine1Doc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CAnimateLine1View message handlers 
 
void CAnimateLine1View::OnDraw(CDC* pDC)  
{ 
/////////////////////我的代码/////////////////// 
    //在客户屏幕上建立一个曲线绘制区域,区域大小为200×100,背景为方格黑背景 
	CRect rect(200,100,401,200); 
	CBrush bkbrush(HS_CROSS,RGB(0,128,0)); 
	pDC->SetBkColor(RGB(0,0,0)); 
    pDC->FillRect(rect,&bkbrush); 
    //创建一个与设备描述表pDC兼容的位图,尺寸为195×100大小,用来保存需要移动的曲线图 
	if(m_dc.GetSafeHdc()==NULL) 
	{ 
	CRect rect1(0,0,195,100); 
    m_dc.CreateCompatibleDC(pDC); 
	m_bmp.CreateCompatibleBitmap(pDC,195,100); 
	m_dc.SelectObject(m_bmp); 
	m_dc.SetBkColor(RGB(0,0,0)); 
	m_dc.FillRect(rect1,&bkbrush); 
	}  
/////////////////////我的代码/////////////////// 
} 
 
void CAnimateLine1View::OnTimer(UINT nIDEvent)  
{ 
/////////////////////我的代码///////////////////    
	CClientDC dc(this); 
    static	int x=200; 
    static int y=200; 
	CPen pen1(PS_SOLID,0,RGB(255,0,8)); 
	CPen *oldpen1=NULL; 
    oldpen1=dc.SelectObject(&pen1); 
	//以下代码用来实现动态曲线 
	x=x+offsetx; 
    //如果曲线没有超出屏幕图片框右边界线,直接在屏幕图片框区域内绘制曲线,不用平移 
    if(x<=400) 
	{ 
	dc.MoveTo(x-offsetx,y); 
    y=200-rand()%90;//模拟数据采样值 
	dc.LineTo(x,y); 
	} 
    //如果曲线超出屏幕图片框右边界线,则需要平移曲线图 
    else 
	{ 
	CRect rect(200,100,401,200); 
	CBrush bkbrush(HS_CROSS,RGB(0,128,0)); 
    m_dc.BitBlt(0,0,195,100,&dc,205,100,SRCCOPY);//保存需要移动的曲线图象 
    //用背景图重绘屏幕图片框,消隐其中的所有曲线 
	dc.SetBkColor(RGB(0,0,0)); 
    dc.FillRect(rect,&bkbrush); 
	//将保存的曲线图向左平移5单位 
    dc.BitBlt(200,100,195,100,&m_dc,0,0,SRCCOPY); 
    //用新数据继续绘制曲线曲线 
	dc.MoveTo(395,y); 
    y=200-rand()%90;//模拟数据采样值 
	dc.LineTo(400,y); 
} 
	dc.SelectObject(oldpen1); 
/////////////////////我的代码/////////////////// 
	CFormView::OnTimer(nIDEvent); 
}