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

📄 水箱实验view.cpp

📁 这是一个水箱的液位控制程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	if(data>4095)		data=4095;	if(data<0)		data=0;	CClientDC dc(this);	Sv=data;	dc.FillRgn(&svRgn,&backBrush);	int m=70+250-(data*250)/4095;    svRgn.OffsetRgn(0,m-_sv);	_sv=m;    dc.FillRgn(&svRgn,&svBrush);}void CMyView::SetSv1(int data){//data是Mv的数字值(满刻度为4095):	if(data>4095)		data=4095;	if(data<0)		data=0;	CClientDC dc(this);	Sv1=data;	dc.FillRgn(&svRgnOther,&backBrush);	int m=620-(data*250)/4095;    svRgnOther.OffsetRgn(0,m-_sv1);	_sv1=m;    dc.FillRgn(&svRgnOther,&svBrush);}void CMyView::OnAorm() {	// TODO: Add your control notification handler code here	// TODO: Add your control notification handler code here	CArom1 dlg;	dlg.m_controlmode1=aorm;	if(dlg.DoModal()==IDOK)	{		if((AfxMessageBox("确定水箱一控制方式吗?",MB_YESNO))==IDYES)		{			CWnd * mWnd=GetDlgItem(IDC_AORM);			if(!((dlg.m_controlmode1==2)&&(aorm2==2)))			{				int aormold=aorm;				aorm=dlg.m_controlmode1;				if(aorm==0)				{					if((StartOK))					{						m_getsetmv1=int(MvData[datanumber-1]*1000);						if(m_getsetmv1<4000)							m_getsetmv1=4000;						else						{							if(m_getsetmv1>20000)								m_getsetmv1=20000;						}											}					mWnd->SetWindowText("MAN(F9)");				}				else 				{					if(aorm==1)						mWnd->SetWindowText("AUTO(F9)");					else					{						if(aormold==1&&aorm==2)						{							m_getsetmv2=m_getsetsv1*4;							U2=float(m_getsetmv2)/1000;						}						mWnd->SetWindowText("SERIES(F9)");					}				}			}			else				AfxMessageBox("不能同时串级!",MB_OK);		}	}}void CMyView::OnAorm2() {	// TODO: Add your control notification handler code here	CArom2 dlg;	dlg.m_controlmode2=aorm2;	if(dlg.DoModal()==IDOK)	{		if((AfxMessageBox("确定水箱二控制方式吗?",MB_YESNO))==IDYES)		{			CWnd * mWnd=GetDlgItem(IDC_AORM2);			if(!((dlg.m_controlmode2==2)&&(aorm==2)))						{				int aorm2old=aorm2;				aorm2=dlg.m_controlmode2;				if(aorm2==0)				{					if((StartOK))					{						m_getsetmv2=int(MvDataOther[datanumber-1]*1000);						if(m_getsetmv2<4000)							m_getsetmv2=4000;						else						{							if(m_getsetmv2>20000)								m_getsetmv2=20000;						}					}					mWnd->SetWindowText("MAN(F10)");				}				else 				{					if(aorm2==1)						mWnd->SetWindowText("AUTO(F10)");					else					{						if(aorm2old==1 && aorm2==2)						{							m_getsetmv1=m_getsetsv2*4;							U1=float(m_getsetmv1)/1000;						}						mWnd->SetWindowText("SERIES(F10)");					}				}			}			else				AfxMessageBox("不能同时串级!",MB_OK);		}	}}void CMyView::OnLButtonDown(UINT nFlags, CPoint point) {	// TODO: Add your message handler code here and/or call default	    if(mvRgn.PtInRegion(point))	{	    SetCapture();	    mvCapture=TRUE;	}	if(svRgn.PtInRegion(point))	{		SetCapture();		svCapture=TRUE;	}	    if(mvRgnOther.PtInRegion(point))	{	    SetCapture();	    mvOtherCapture=TRUE;	}	if(svRgnOther.PtInRegion(point))	{		SetCapture();		svOtherCapture=TRUE;	}		CFormView::OnLButtonDown(nFlags, point);}void CMyView::OnLButtonUp(UINT nFlags, CPoint point) {	// TODO: Add your message handler code here and/or call default	int temp=point.y;	if(svCapture&&(((aorm==1)&&!(aorm2==2))||((aorm==1)&&(aorm2==2))))	{		m_getsetsv1=(320-temp)*4000/250+1000;		if(m_getsetsv1>5000)			m_getsetsv1=5000;///**		else		{			if(m_getsetsv1<1000)				m_getsetsv1=1000;		}		//m_getsetsv1;	}	if(svOtherCapture&&((!(aorm==2)&&(aorm2==1))||((aorm==2)&&(aorm2==1))))	{		m_getsetsv2=(620-temp)*4000/250+1000;		if(m_getsetsv2>5000)			m_getsetsv2=5000;		else		{			if(m_getsetsv2<1000)				m_getsetsv2=1000;		}		//U2=float(m_getsetsv2);////**	}		if(mvCapture&&(((aorm==0)&&!(aorm2==2))||((aorm==0)&&(aorm2==2))))	{		m_getsetmv1=(320-temp)*16000/250+4000;		if(m_getsetmv1>20000)			m_getsetmv1=20000;		else		{			if(m_getsetmv1<4000)				m_getsetmv1=4000;		}		U1=float(m_getsetmv1)/1000;		if(aorm2==2)			m_getsetsv2=m_getsetmv1/4;	}	if(mvOtherCapture&&(((aorm2==0)&&!(aorm==2))||((aorm==2)&&(aorm2==0))))	{		m_getsetmv2=(620-temp)*16000/250+4000;		if(m_getsetmv2>20000)			m_getsetmv2=20000;		else		{			if(m_getsetmv2<4000)				m_getsetmv2=4000;		}		U2=float(m_getsetmv2)/1000;		if(aorm==2)			m_getsetsv1=m_getsetmv2/4;	}		ReleaseCapture();	mvCapture=FALSE;	svCapture=FALSE;	mvOtherCapture=FALSE;	svOtherCapture=FALSE;		CFormView::OnLButtonUp(nFlags, point);}void CMyView::OnMouseMove(UINT nFlags, CPoint point) {	// TODO: Add your message handler code here and/or call default	int temp=point.y;	if(mvCapture&&(((aorm==0)&&!(aorm2==2))||((aorm==0)&&(aorm2==2))))	{		CClientDC dc(this);        dc.FillRgn(&mvRgn,&backBrush);		if(temp<70)			temp=70;		if(temp>320)            temp=320;		mvRgn.OffsetRgn(0,temp-_mv);		_mv=temp;		Mv=(320-_mv)*250/4095;	    dc.FillRgn(&mvRgn,&mvBrush);		GetParent()->PostMessage(MVCHANGE_DATA,Mv,0);			}	if(svCapture&&(((aorm==1)&&!(aorm2==2))||((aorm==1)&&(aorm2==2))))	{		CClientDC dc(this);        dc.FillRgn(&svRgn,&backBrush);		if(temp<70)			temp=70;		if(temp>320)            temp=320;		svRgn.OffsetRgn(0,temp-_sv);		_sv=temp;		Sv=(320-_sv)*250/4095;	    dc.FillRgn(&svRgn,&svBrush);		GetParent()->PostMessage(SVCHANGE_DATA,Sv,0);	}	if(mvOtherCapture&&(((aorm2==0)&&!(aorm==2))||((aorm==2)&&(aorm2==0))))	{		CClientDC dc(this);        dc.FillRgn(&mvRgnOther,&backBrush);		if(temp<370)			temp=370;		if(temp>620)            temp=620;		mvRgnOther.OffsetRgn(0,temp-_mv1);		_mv1=temp;		Mv1=(620-_mv1)*200/4095;	    dc.FillRgn(&mvRgnOther,&mvBrush);		GetParent()->PostMessage(MVCHANGE_DATA,Mv1,0);			}	if(svOtherCapture&&((!(aorm==2)&&(aorm2==1))||((aorm==2)&&(aorm2==1))))	{		CClientDC dc(this);        dc.FillRgn(&svRgnOther,&backBrush);		if(temp<370)			temp=370;		if(temp>620)            temp=620;		svRgnOther.OffsetRgn(0,temp-_sv1);		_sv1=temp;		Mv1=(620-_mv1)*200/4095;	    dc.FillRgn(&svRgnOther,&svBrush);		GetParent()->PostMessage(SVCHANGE_DATA,Sv1,0);			}		CFormView::OnMouseMove(nFlags, point);}void CMyView::OnSave() {	// TODO: Add your control notification handler code here	char BASED_CODE szFilter[30]="Data File(*.data)||";	CFileDialog fdlg(FALSE,"data",NULL,		OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter,this);	fdlg.DoModal();	CString filename=fdlg.GetFileName();	CFile file;	if(file.Open(filename.GetBuffer(MAX_PATH),CFile::modeCreate|CFile::modeWrite))    {		file.Write(&m_pidcontrolget,sizeof(m_pidcontrolget));		file.Write(&datanumber,sizeof(datanumber));		file.Write(&m_time,sizeof(m_time));		file.Write(PvData,sizeof(PvData));		file.Write(MvData,sizeof(MvData));		file.Write(SvData,sizeof(SvData));		file.Write(PvDataOther,sizeof(PvDataOther));		file.Write(MvDataOther,sizeof(MvDataOther));		file.Write(SvDataOther,sizeof(SvDataOther));		file.Close();	}	}void CMyView::OnRead() {	// TODO: Add your control notification handler code here	char BASED_CODE szFilter[30]="Data File(*.data)||";	CFileDialog fdlg(TRUE,"data",NULL,		OFN_HIDEREADONLY,szFilter,this);	fdlg.DoModal();	CString filename=fdlg.GetFileName();	CFile file;	if(file.Open(filename.GetBuffer(MAX_PATH),CFile::modeRead))    {		file.Read(&m_pidcontrolget,sizeof(m_pidcontrolget));		file.Read(&datanumber,sizeof(datanumber));		file.Read(&m_time,sizeof(m_time));		file.Read(PvData,sizeof(PvData));		file.Read(MvData,sizeof(MvData));		file.Read(SvData,sizeof(SvData));		file.Read(PvDataOther,sizeof(PvDataOther));		file.Read(MvDataOther,sizeof(MvDataOther));		file.Read(SvDataOther,sizeof(SvDataOther));		file.Close();	    CClientDC dc(this);        CRect fRect(50,69,850,320);		CRect fRect1(50,369,850,620);	    CBrush br(RGB(0,0,0));           //CBrush br(RGB(255,255,255));//论文打印时改变		CBrush br1(RGB(m_showbkwhite1?255:0,m_showbkwhite1?255:0,m_showbkwhite1?255:0));		CBrush br2(RGB(m_showbkwhite2?255:0,m_showbkwhite2?255:0,m_showbkwhite2?255:0));	    dc.FillRect(fRect,&br1);		dc.FillRect(fRect1,&br2);		Move=1;		clean=1;		Displaydata();	}}void CMyView::OnFileOpen() {	// TODO: Add your command handler code here	char BASED_CODE szFilter[30]="Data File(*.data)||";	CFileDialog fdlg(TRUE,"data",NULL,		OFN_HIDEREADONLY,szFilter,this);	fdlg.DoModal();	CString filename=fdlg.GetFileName();	CFile file;	if(file.Open(filename.GetBuffer(MAX_PATH),CFile::modeRead))    {		file.Read(&m_pidcontrolget,sizeof(m_pidcontrolget));		file.Read(&datanumber,sizeof(datanumber));		file.Read(&m_time,sizeof(m_time));		file.Read(PvData,sizeof(PvData));		file.Read(MvData,sizeof(MvData));		file.Read(SvData,sizeof(SvData));		file.Read(PvDataOther,sizeof(PvDataOther));		file.Read(MvDataOther,sizeof(MvDataOther));		file.Read(SvDataOther,sizeof(SvDataOther));		file.Close();	    CClientDC dc(this);        CRect fRect(50,69,850,320);		CRect fRect1(50,369,850,620);	    CBrush br(RGB(0,0,0));              //CBrush br(RGB(255,255,255));//论文打印时改变		CBrush br1(RGB(m_showbkwhite1?255:0,m_showbkwhite1?255:0,m_showbkwhite1?255:0));		CBrush br2(RGB(m_showbkwhite2?255:0,m_showbkwhite2?255:0,m_showbkwhite2?255:0));	    dc.FillRect(fRect,&br1);		dc.FillRect(fRect1,&br2);		Move=1;		clean=1;		Displaydata();			}}void CMyView::OnFileSaveAs() {	// TODO: Add your command handler code here		char BASED_CODE szFilter[30]="Data File(*.data)||";	CFileDialog fdlg(FALSE,"data",NULL,		OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter,this);	fdlg.DoModal();	CString filename=fdlg.GetFileName();	CFile file;	if(file.Open(filename.GetBuffer(MAX_PATH),CFile::modeCreate|CFile::modeWrite))    {		file.Write(&m_pidcontrolget,sizeof(m_pidcontrolget));		file.Write(&datanumber,sizeof(datanumber));		file.Write(&m_time,sizeof(m_time));		file.Write(PvData,sizeof(PvData));		file.Write(MvData,sizeof(MvData));		file.Write(SvData,sizeof(SvData));		file.Write(PvDataOther,sizeof(PvDataOther));		file.Write(MvDataOther,sizeof(MvDataOther));		file.Write(SvDataOther,sizeof(SvDataOther));		file.Close();	}	}void CMyView::OnHistorydata() {	// TODO: Add your control notification handler code here	if(datanumber>0)	{	Chistorydata dlg;	dlg.m_historytimeget1=m_historytimeget1;	dlg.m_historytimeget2=m_historytimeget2;	dlg.historymv1=MvData[(m_historytimeget1*1000/m_time)*5];	dlg.historysv1=SvData[(m_historytimeget1*1000/m_time)*5];		dlg.historypv1=PvData[(m_historytimeget1*1000/m_time)*5+1];		dlg.historymv2=MvDataOther[(m_historytimeget2*1000/m_time)*5];	dlg.historysv2=SvDataOther[(m_historytimeget2*1000/m_time)*5];	dlg.historypv2=PvDataOther[(m_historytimeget2*1000/m_time)*5];		if(dlg.DoModal()==IDOK)	{		if((dlg.m_historytimeget1*1000/m_time)*5<int(datanumber)&&(dlg.m_historytimeget2*1000/m_time)*5<int(datanumber))		{			m_historytimeget1=dlg.m_historytimeget1;			dlg.historymv1=MvData[(m_historytimeget1*1000/m_time)*5];			dlg.historysv1=SvData[(m_historytimeget1*1000/m_time)*5];			dlg.historypv1=PvData[(m_historytimeget1*1000/m_time)*5+1];				m_historytimeget2=dlg.m_historytimeget2;			dlg.historymv2=MvDataOther[(m_historytimeget2*1000/m_time)*5];			dlg.historysv2=SvDataOther[(m_historytimeget2*1000/m_time)*5];			dlg.historypv2=PvDataOther[(m_historytimeget2*1000/m_time)*5];			dlg.DoModal();		}		else			AfxMessageBox("时间超出记录范围!",MB_OK);			}}}void CMyView::OnOptionHistorydata() {	// TODO: Add your command handler code here	if(datanumber>0)	{	Chistorydata dlg;	dlg.m_historytimeget1=m_historytimeget1;	dlg.m_historytimeget2=m_historytimeget2;	dlg.historymv1=MvData[(m_historytimeget1*1000/m_time)*5];	dlg.historysv1=SvData[(m_historytimeget1*1000/m_time)*5];		dlg.historypv1=PvData[(m_historytimeget1*1000/m_time)*5+1];		dlg.historymv2=MvDataOther[(m_historytimeget2*1000/m_time)*5];	dlg.historysv2=SvDataOther[(m_historytimeget2*1000/m_time)*5];	dlg.historypv2=PvDataOther[(m_historytimeget2*1000/m_time)*5];		if(dlg.DoModal()==IDOK)	{		if((dlg.m_historytimeget1*1000/m_time)*5<int(datanumber)&&(dlg.m_historytimeget2*1000/m_time)*5<int(datanumber))		{			m_historytimeget1=dlg.m_historytimeget1;			dlg.historymv1=MvData[(m_historytimeget1*1000/m_time)*5];			dlg.historysv1=SvData[(m_historytimeget1*1000/m_time)*5];			dlg.historypv1=PvData[(m_historytimeget1*1000/m_time)*5+1];				m_historytimeget2=dlg.m_historytimeget2;			dlg.historymv2=MvDataOther[(m_historytimeget2*1000/m_time)*5];			dlg.historysv2=SvDataOther[(m_historytimeget2*1000/m_time)*5];			dlg.historypv2=PvDataOther[(m_historytimeget2*1000/m_time)*5];			dlg.DoModal();		}		else			AfxMessageBox("时间超出记录范围!",MB_OK);			}}}void CMyView::OnSystemDelaytime() {	// TODO: Add your command handler code here	Cdelaytime dlg;	dlg.m_delaytime1=m_delaytime1;	dlg.m_delaytime2=m_delaytime2;	if(dlg.DoModal()==IDOK)	{		if(!StartOK)		{			if((AfxMessageBox("Is sure to change?",MB_YESNO))==IDYES)

⌨️ 快捷键说明

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