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

📄 powerview.cpp

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

#include "stdafx.h"
#include "afx.h"
#include "power.h"

#include "powerDoc.h"
#include "powerView.h"
#include "asmdlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPowerView

IMPLEMENT_DYNCREATE(CPowerView, CFormView)

BEGIN_MESSAGE_MAP(CPowerView, CFormView)
	//{{AFX_MSG_MAP(CPowerView)
	ON_COMMAND(ID_ASMTEST, OnAsmtest)
	//}}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)
	ON_MESSAGE(WM_ASMPRINTORPREVIEW,OnAsmPrintOrPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPowerView construction/destruction

CPowerView::CPowerView():CFormView(IDD_FORMVIEW)
{
	// TODO: add construction code here
	
	m_pAsmDlg=new CAsmDlg(this);

}

CPowerView::~CPowerView()
{
	delete m_pAsmDlg;
}

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

	return CFormView::PreCreateWindow(cs);
}




/////////////////////////////////////////////////////////////////////////////
// CPowerView drawing

void CPowerView::OnDraw(CDC* pDC)
{

	CPowerDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here


}

/////////////////////////////////////////////////////////////////////////////
// CPowerView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CPowerView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CPowerView message handlers



LRESULT CPowerView::OnAsmPrintOrPreview(WPARAM wParam,LPARAM lParam)
{

	if(m_pAsmDlg->GetSafeHwnd()!=0)
	{
		switch(wParam)
		{
			case ASMPRINTPREVIEW://实时曲线打印预览
				CView::OnFilePrintPreview();
				break;
			case ASMPRINT://实时曲线打印
				CView::OnFilePrint();break;
			case ASMEND://
				m_pAsmDlg->DestroyWindow();
				break;
			default:break;
		}
	}

	return 0L;
}

void CPowerView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	

}






void CPowerView::OnAsmtest() 
{
	// TODO: Add your command handler code here

	if(m_pAsmDlg->GetSafeHwnd()==0)
		m_pAsmDlg->Create();

}

void CPowerView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	if(m_pAsmDlg->GetSafeHwnd()!=0)
	{
		CRect oldrect;
		clPlot &plot=m_pAsmDlg->m_asmrealtime;//引用

		plot.GetDiagramRect(oldrect);//保存原来设置图形的大小

		CSize sizePrint(pDC->GetDeviceCaps(HORZRES),pDC->GetDeviceCaps(VERTRES));
		sizePrint.cy/=2;//设置为半张打印纸大小
		pInfo->m_rectDraw.SetRect(0,0,sizePrint.cx,sizePrint.cy);
		pInfo->m_rectDraw.DeflateRect(sizePrint.cx/20,sizePrint.cy/20);//留margin

		
		plot.SetDiagramRect(pInfo->m_rectDraw,pDC);//设置打印图形的大小(象素)


		long oldfrom,oldto;
		long from=0,to;
		plot.GetXFromToTime(oldfrom,oldto);//保存原来图形的X轴起始值(实际值,ms)
		to=oldto;
		
		plot.SetBXRange(from,to,false);//设置新的X轴起始值(画整张图)
		plot.Print(pDC);//在打印机上打印

		plot.SetBXRange(oldfrom,oldto);//恢复原来图形的X轴起始值(实际值,ms)
		plot.SetDiagramRect(oldrect);//恢复原来设置图形的大小(象素)

	}
}

⌨️ 快捷键说明

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