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

📄 asmdlg.cpp

📁 实时曲线类的改进增加功能: 1)采样数据存盘和加载 2)演示程序中可以实现图形的打印预览和打印功能,曲线从原点开始
💻 CPP
字号:
// AsmDlg.cpp : implementation file
//

#include "stdafx.h"
#include "power.h"
#include "AsmDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAsmDlg dialog



CAsmDlg::CAsmDlg(CView *pView)
{
	m_pView=pView;
	m_bPausing=false;
	m_bFirstStart=true;
	m_offPlotToDlg=CRect(0,0,0,0);
}

BOOL CAsmDlg::Create()
{
	m_bFirstStart=true;
	m_bCanSize=false;
	return CDialog::Create(CAsmDlg::IDD);
}

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


BEGIN_MESSAGE_MAP(CAsmDlg, CDialog)
	//{{AFX_MSG_MAP(CAsmDlg)
	ON_BN_CLICKED(IDC_ASMPRINTPREVIEW, OnAsmprintpreview)
	ON_BN_CLICKED(IDC_ASMPRINT, OnAsmprint)
	ON_BN_CLICKED(IDC_ASMSTART, OnAsmstart)
	ON_BN_CLICKED(IDC_ASMPAUSE, OnAsmpause)
	ON_WM_SIZE()
	ON_WM_TIMER()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_ASMDATASTORE, OnAsmdatastore)
	ON_BN_CLICKED(IDC_ASMDATASLOAD, OnAsmdatasload)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAsmDlg message handlers


void CAsmDlg::OnAsmprintpreview() 
{
	// TODO: Add your control notification handler code here

	m_pView->PostMessage(WM_ASMPRINTORPREVIEW,ASMPRINTPREVIEW);


}

void CAsmDlg::OnAsmprint() 
{
	// TODO: Add your control notification handler code here
	m_pView->PostMessage(WM_ASMPRINTORPREVIEW,ASMPRINT);
	
}

void CAsmDlg::OnAsmstart() 
{
	// TODO: Add your control notification handler code here

	m_lStartTime=timeGetTime();
	long curtime=0;
	double y=0.0;
	m_asmrealtime.Reset();
	m_asmrealtime.AddPoint(0,curtime, y);
	SetTimer(1,1000,NULL);

	if(m_bFirstStart)
	{
		CButton *bt;
		bt=(CButton *)GetDlgItem(IDC_ASMSTART);
		m_bFirstStart=false;
		bt->SetWindowText("重新开始");
	}
	else
	{
		CButton *bt;
		bt=(CButton *)GetDlgItem(IDC_ASMPAUSE);
		m_bPausing=false;
		bt->SetWindowText("暂停");
	}
	
}

void CAsmDlg::OnAsmpause() 
{
	// TODO: Add your control notification handler code here
	CButton *bt;
	bt=(CButton *)GetDlgItem(IDC_ASMPAUSE);
	if(m_bPausing)
	{
		SetTimer(1,1000,NULL);
		m_bPausing=false;
		bt->SetWindowText("暂停");
	}
	else
	{
		KillTimer(1);
		m_bPausing=true;
		bt->SetWindowText("继续");
	}
	
}

BOOL CAsmDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here

	
	TRACE(" OnInitDialog  \n");
	m_bPausing=false;               //暂停按钮现在为“非暂停”状态
	CRect Rect;
	
	//计算实时曲线区域坐标
	CWnd *pd=(CWnd *)GetDlgItem(IDC_ASMREALTIME);
	pd->GetClientRect(&Rect);//control logic  coordinate
	pd->ClientToScreen(&Rect);//screen coordinate
	ScreenToClient(&Rect);//CView logic coordinate

	m_asmrealtime.m_bAutoScrollX=true;
	//m_asmrealtime.m_bUseRightYAxis=false;//单Y轴(默认)
	m_asmrealtime.SetSerie(0, PS_SOLID, RGB(255,0,0), 0.0, 75.0, "速度:km/h");

	m_asmrealtime.Create(WS_CHILD|WS_VISIBLE,Rect,this,12000);//创建并显示

	CRect lrect;
	GetClientRect(&lrect);

	m_offPlotToDlg=Rect;
	m_offPlotToDlg.DeflateRect(&lrect);
	
	pd=(CWnd *)GetDlgItem(IDC_ASMSTART);
	pd->GetClientRect(&Rect);//control logic  coordinate
	pd->ClientToScreen(&Rect);//device coordinate
	ScreenToClient(&Rect);// logic coordinate
	
	m_offBt.cx=lrect.right-Rect.left;
	m_offBt.cy=lrect.bottom-Rect.bottom;


	m_bCanSize=TRUE;//允许实时曲线区域调整大小

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE

  }

void CAsmDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	TRACE(" Onsize \n");
	if(m_bCanSize)
	{

		CRect Rect;
		Rect=m_offPlotToDlg;
		Rect.right=cx+m_offPlotToDlg.right;
		Rect.bottom=cy+m_offPlotToDlg.bottom;

		CWnd *pd;
		int myid[]={IDC_ASMSTART,IDC_ASMPAUSE,IDC_ASMPRINT,IDC_ASMPRINTPREVIEW,IDC_ASMDATASLOAD,IDC_ASMDATASTORE,IDOK,IDCANCEL};
		CRect lrect;

    	for(int i=0;i<8;i++)
		{//调整各个按钮的位置
			lrect=m_offPlotToDlg;
			pd=(CWnd *)GetDlgItem(myid[i]);
			pd->GetClientRect(&lrect);
			pd->ClientToScreen(&lrect);//screen coordinate
			ScreenToClient(&lrect);//logic coordinate
			CSize size(lrect.Width(),lrect.Height());
			lrect.left=cx-m_offBt.cx;
			pd->SetWindowPos(NULL,lrect.left,lrect.top,size.cx,size.cy,SWP_SHOWWINDOW);
		}
			
			
		pd=(CWnd *)GetDlgItem(IDC_ASMREALTIME);
		pd->SetWindowPos(NULL,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_SHOWWINDOW);
		Invalidate();
		pd->GetClientRect(&Rect);
		pd->ClientToScreen(&Rect);//device coordinate
		ScreenToClient(&Rect);//control parent window's logic coordinate
		m_asmrealtime.MoveWindow(Rect);//调整实时曲线区域的大小
  }
	
}

void CAsmDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	static BOOL pros={FALSE};
	//if(!pros)
	{
		
		double y =(double)(abs(rand())%60);//模拟数据
	
		long curtime=timeGetTime()-m_lStartTime;
		m_asmrealtime.AddPoint(0,  curtime, y);

		m_asmrealtime.Invalidate();//重画实时曲线窗口

		//pros=FALSE;

	}
	
	CDialog::OnTimer(nIDEvent);
}

void CAsmDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	m_asmrealtime.Reset();//复位使其内部状态恢复为原始状态
	m_pView->PostMessage(WM_ASMPRINTORPREVIEW,ASMEND);//销毁对话框窗口,而非对象

}

void CAsmDlg::OnOK() 
{
	// TODO: Add extra validation here
	
	m_asmrealtime.Reset();//复位使其内部状态恢复为原始状态
	m_pView->PostMessage(WM_ASMPRINTORPREVIEW,ASMEND);//销毁对话框窗口,而非对象
}

void CAsmDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	TRACE(" paint\n");
	
	// TODO: Add your message handler code here
	

	// Do not call CDialog::OnPaint() for painting messages
}

void CAsmDlg::OnAsmdatastore() 
{
	// TODO: Add your control notification handler code here
	m_asmrealtime.StoreToFile();//数据存盘
	
}

void CAsmDlg::OnAsmdatasload() 
{
	// TODO: Add your control notification handler code here
	m_asmrealtime.LoadFromFile();//加载历史数据
	
}


⌨️ 快捷键说明

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