📄 control_temview.cpp
字号:
// CONTROL_TEMView.cpp : implementation of the CCONTROL_TEMView class
//
#include "stdafx.h"
#include "CONTROL_TEM.h"
#include "CONTROL_TEMDoc.h"
#include "CONTROL_TEMView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCONTROL_TEMView
#include"dlg.h"
extern double de,begin,end;
IMPLEMENT_DYNCREATE(CCONTROL_TEMView, CView)
BEGIN_MESSAGE_MAP(CCONTROL_TEMView, CView)
//{{AFX_MSG_MAP(CCONTROL_TEMView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
ON_COMMAND(ID_MENU_INPUT, OnMenuInput)
ON_COMMAND(ID_MENU_RUN, OnMenuRun)
ON_WM_TIMER()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCONTROL_TEMView construction/destruction
/***********构造函数*************/
CCONTROL_TEMView::CCONTROL_TEMView()
{
// TODO: add construction code here
xaxis[0].x=100;
xaxis[0].y=150;
xaxis[1].x=500;
xaxis[1].y=150;
yaxis[0].x=100;
yaxis[0].y=50;
yaxis[1].x=100;
yaxis[1].y=250;
flag=0;flag1=0;
n=0;
m_nviewe=250;
ww[0].x=100;
ww[0].y=250;
}
CCONTROL_TEMView::~CCONTROL_TEMView()
{
}
BOOL CCONTROL_TEMView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCONTROL_TEMView drawing
void CCONTROL_TEMView::OnDraw(CDC* pDC)
{
CCONTROL_TEMDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if((flag==1)&&(flag1==0))
{
CFont fnt;
LOGFONT logfnt={
5,10,0,0,FW_HEAVY,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Arial"};
fnt.CreatePointFontIndirect(&logfnt);
pDC->SelectObject(&fnt);
pDC->SetTextColor(RGB(0,0,0));
pDC->TextOut(300,30,"温度变化曲线图");
// pDC->TextOut(50,370,"色块");
fnt.DeleteObject();
LOGFONT logfnt1={
5,10,0,0,0,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"Arial"};
fnt.CreatePointFontIndirect(&logfnt1);
pDC->SelectObject(&fnt);
pDC->SetTextColor(RGB(0,0,0));
pDC->TextOut(450,330,"W:");///////
char szW[10];
sprintf(szW,"%f",w);
pDC->TextOut(490,330,szW);
pDC->TextOut(450,370,"T:");////////
sprintf(szW,"%f",begin);
pDC->TextOut(490,370,szW);
fnt.DeleteObject();
/********画坐标轴***************/
pDC->MoveTo(xaxis[0]);
pDC->LineTo(xaxis[1]);
pDC->MoveTo(100,50);
pDC->LineTo(96,58);
pDC->MoveTo(100,50);
pDC->LineTo(104,58);
pDC->MoveTo(500,150);
pDC->LineTo(493,146);
pDC->MoveTo(500,150);
pDC->LineTo(493,154);
pDC->MoveTo(yaxis[0]);
pDC->LineTo(yaxis[1]);
pDC->TextOut(40,140,"目标T0");
pDC->TextOut(54,38,"温度T");
pDC->TextOut(460,155,"时间t");
pDC->TextOut(280,350,"功率和温度的变化情况");
/******************画毕*******************/
for(int i=0;i<n-1;i++)
{
pDC->MoveTo(ww[i]);
pDC->LineTo(ww[i+1]);
}
/***************创建画笔**************/
CPen p;
p.CreatePen(PS_DASHDOT,3,RGB(255,255,0));/*画笔颜色为黄色*/
pDC->SelectObject(&p);
pDC->MoveTo(0,300);
pDC->LineTo(900,300);
pDC->MoveTo(100,300);
pDC->LineTo(100,900);
pDC->MoveTo(100,500);
pDC->LineTo(900,500);
pDC->MoveTo(900,300);
pDC->LineTo(900,500);
p.DeleteObject();
/***************创建画刷*画色块**********/
// CBrush br;
// br.CreateSolidBrush(RGB(m_nviewe*10+120,m_nviewe+12,m_nviewe*10+120));
// pDC->SelectObject(&br);
// pDC->Rectangle(150,350,250,400);
// br.DeleteObject();
}
}
/////////////////////////////////////////////////////////////////////////////
// CCONTROL_TEMView printing
BOOL CCONTROL_TEMView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCONTROL_TEMView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCONTROL_TEMView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCONTROL_TEMView diagnostics
#ifdef _DEBUG
void CCONTROL_TEMView::AssertValid() const
{
CView::AssertValid();
}
void CCONTROL_TEMView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCONTROL_TEMDoc* CCONTROL_TEMView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCONTROL_TEMDoc)));
return (CCONTROL_TEMDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCONTROL_TEMView message handlers
void CCONTROL_TEMView::OnMenuInput()
{
// TODO: Add your command handler code here
flag=0;
Invalidate(TRUE);
dlg Dlg;
if(Dlg.DoModal()==IDOK)
{
begin=Dlg.m_chushi;//初始温度
end=Dlg.m_zhongzhi;//目标温度
de=Dlg.m_bianhualv;//变化率
flag1=0;
if(begin>6||begin<-6||end>6||end<-6||de>6||de<-6)
{
flag1=1;
begin=0;
end=0;
de=0;
}
if(flag1==1)
{
}
Invalidate();
}
l.putvalue();
}
//-----------------------------------------
//----------------------------------------
void CCONTROL_TEMView::OnMenuRun()
{
// TODO: Add your command handler code here
n=0;
ww[0].y=150+int(l.getne());
n++;
SetTimer(1,100,NULL);
}
void CCONTROL_TEMView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
flag=1;
int i=0;
if(l.getde()>0.01||l.getde()<-0.01||l.getne()>0.01||l.getne()<-0.01)
{
m_nviewe=l.getne();
w=l.fuzzification();
Invalidate(TRUE);
l.modify(w);
i++;
ww[n].x=ww[n-1].x+1;
ww[n].y=150.0+m_nviewe*10.0;
n++;
}
else
KillTimer(1);
CView::OnTimer(nIDEvent);
}
void CCONTROL_TEMView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CView::OnPrint(pDC, pInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -