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

📄 animateline2view.cpp

📁 电脑编程技巧与维护200109期杂志源代码
💻 CPP
字号:
// AnimateLine2View.cpp : implementation of the CAnimateLine2View class
//

#include "stdafx.h"
#include "AnimateLine2.h"

#include "AnimateLine2Doc.h"
#include "AnimateLine2View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAnimateLine2View

IMPLEMENT_DYNCREATE(CAnimateLine2View, CFormView)

BEGIN_MESSAGE_MAP(CAnimateLine2View, CFormView)
	//{{AFX_MSG_MAP(CAnimateLine2View)
	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()

/////////////////////////////////////////////////////////////////////////////
// CAnimateLine2View construction/destruction

CAnimateLine2View::CAnimateLine2View()
	: CFormView(CAnimateLine2View::IDD)
{
	//{{AFX_DATA_INIT(CAnimateLine2View)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CAnimateLine2View::~CAnimateLine2View()
{
}

void CAnimateLine2View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAnimateLine2View)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BOOL CAnimateLine2View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CAnimateLine2View::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
/////////////////////我的代码///////////////////
	//以下代码意味着:曲线每隔200毫秒前进5单元水平距离
    offsetx=5;
    SetTimer(1,200,NULL);
/////////////////////我的代码///////////////////
}

/////////////////////////////////////////////////////////////////////////////
// CAnimateLine2View printing

BOOL CAnimateLine2View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CAnimateLine2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CAnimateLine2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CAnimateLine2View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CAnimateLine2View diagnostics

#ifdef _DEBUG
void CAnimateLine2View::AssertValid() const
{
	CFormView::AssertValid();
}

void CAnimateLine2View::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CAnimateLine2Doc* CAnimateLine2View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimateLine2Doc)));
	return (CAnimateLine2Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CAnimateLine2View message handlers

void CAnimateLine2View::OnTimer(UINT nIDEvent) 
{
/////////////////////我的代码///////////////////
    static	int x=0;
    static int y=0;
	static int control=0;
	//以下代码用来实现实时动态曲线
	CClientDC dc(this);
	CRect rect(0,0,200,100);
	CRect rect1(200,0,400,100);
	CBrush bkbrush(HS_CROSS,RGB(0,128,0));
	x=x+offsetx;
    CPen pen1(PS_SOLID,0,RGB(255,0,8));
	CPen *oldpen1=NULL;
    oldpen1=m_dc.SelectObject(&pen1);
    //如果曲线没有超出辅助图片框的中间线时,进行以下操作
    if(x<=200)
	{
    //在辅助图片框中画曲线	
	m_dc.MoveTo(x-offsetx,y);
    y=100-rand()%90;//模拟数据采样值
	m_dc.LineTo(x,y);
    //将辅助图片框中的曲线拷贝到屏幕图片框中
	     if(control==0)
		 {
	      dc.BitBlt(200,100,200,100,&m_dc,0,0,SRCCOPY);
		 }
	     else
		 {
	      dc.BitBlt(200,100,200-x,100,&m_dc,200+x,0,SRCCOPY);
	      dc.BitBlt(400-x,100,x,100,&m_dc,0,0,SRCCOPY);
		 }
	}
    //如果曲线超过辅助图片框的中间线但还没到达辅助图片框右边界线时,进行以下操作
    if(x<=400&&x>200)
	{
   	     if(control==1)   	
		 {
	      dc.BitBlt(200,100,200,100,&m_dc,x-200,0,SRCCOPY);
	      m_dc.FillRect(rect1,&bkbrush);
	      control=0;
		 }
    //在辅助图片框中画曲线	
	m_dc.MoveTo(x-offsetx,y);
    y=100-rand()%90;//模拟数据采样值
	m_dc.LineTo(x,y);
    //将辅助图片框中的曲线拷贝到屏幕图片框中
	dc.BitBlt(200,100,200,100,&m_dc,x-200,0,SRCCOPY);
	}
    //如果曲线到达辅助图片框右边界线时,进行以下操作
    if(x>400)
	{	
    x=0;
	dc.BitBlt(200,100,200-x,100,&m_dc,200+x,0,SRCCOPY);
	dc.BitBlt(400-x,100,x,100,&m_dc,0,0,SRCCOPY);
	m_dc.SetBkColor(RGB(0,0,0));
	m_dc.FillRect(rect,&bkbrush);
	control=1;
	}
	dc.SelectObject(oldpen1);
/////////////////////我的代码///////////////////
	CFormView::OnTimer(nIDEvent);
}

void CAnimateLine2View::OnDraw(CDC* pDC) 
{
/////////////////////我的代码///////////////////
	//创建一个辅助曲线画图框,画图框的大小为400×100,背景为方格黑背景
	CBrush bkbrush(HS_CROSS,RGB(0,128,0));
	CRect rc(0,0,400,100);
	if(m_dc.GetSafeHdc()==NULL)
	{
    m_dc.CreateCompatibleDC(pDC);
	m_bmp.CreateCompatibleBitmap(pDC,400,100);
	m_dc.SelectObject(m_bmp);
	m_dc.SetBkColor(RGB(0,0,0));
	m_dc.FillRect(rc,&bkbrush);
	}	
/////////////////////我的代码///////////////////
}

⌨️ 快捷键说明

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