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

📄 cehuangyiview.cpp

📁 一个毕业设计。用vc编写的一个简易测谎仪后台软件。用控件实现access数据库的链接
💻 CPP
字号:
// cehuangyiView.cpp : implementation of the CCehuangyiView class
//

#include "stdafx.h"
#include "cehuangyi.h"

#include "cehuangyiSet.h"
#include "cehuangyiDoc.h"
#include "cehuangyiView.h"
#include "test.h"
#include "wenti.h"
#include "wentiset.h"
#include "people.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCehuangyiView

IMPLEMENT_DYNCREATE(CCehuangyiView, CRecordView)

BEGIN_MESSAGE_MAP(CCehuangyiView, CRecordView)
	//{{AFX_MSG_MAP(CCehuangyiView)
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_PEOPLE, OnPeople)
	ON_BN_CLICKED(IDC_QUESTION, OnQuestion)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCehuangyiView construction/destruction

CCehuangyiView::CCehuangyiView()
	: CRecordView(CCehuangyiView::IDD)
{
	//{{AFX_DATA_INIT(CCehuangyiView)
	m_pSet = NULL;
	m_survey = NULL;
	m_name = _T("");
	m_wenti = _T("");
	m_wentiid = _T("");
	m_nanswer = -1;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CCehuangyiView::~CCehuangyiView()
{
}

void CCehuangyiView::DoDataExchange(CDataExchange* pDX)
{
	CRecordView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCehuangyiView)
	DDX_Text(pDX, IDC_NAME, m_name);
	DDX_Text(pDX, IDC_WENTI, m_wenti);
	DDX_Text(pDX, IDC_WENTIID, m_wentiid);
	DDX_Radio(pDX, IDC_YES, m_nanswer);
	//}}AFX_DATA_MAP
}

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

	return CRecordView::PreCreateWindow(cs);
}

void CCehuangyiView::OnInitialUpdate()
{
	m_pSet = &GetDocument()->m_cehuangyiSet;
	m_survey = &GetDocument()->m_surveyset;
	CRecordView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
	m_survey->Open();

}

/////////////////////////////////////////////////////////////////////////////
// CCehuangyiView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCehuangyiView diagnostics

#ifdef _DEBUG
void CCehuangyiView::AssertValid() const
{
	CRecordView::AssertValid();
}

void CCehuangyiView::Dump(CDumpContext& dc) const
{
	CRecordView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CCehuangyiView database support
CRecordset* CCehuangyiView::OnGetRecordset()
{
	return m_pSet;
	return m_survey;
}


/////////////////////////////////////////////////////////////////////////////
// CCehuangyiView message handlers



void CCehuangyiView::OnStart() 
{
	// TODO: Add your control notification handler code here
	if (bfirst){
		DCB dcb;
	 
        hcom=CreateFile("COM2",GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);// OPEN COM
	    if (hcom==(HANDLE)-1)
		{
			MessageBox("com error");
	   
		}
		BuildCommDCB("COM2",&dcb);//配置串口
		SetCommState(hcom,&dcb);

		COMMTIMEOUTS CommTimeOuts;
		CommTimeOuts.ReadIntervalTimeout = 0xFFFFFFFF;
		CommTimeOuts.ReadTotalTimeoutMultiplier = 0;
		CommTimeOuts.ReadTotalTimeoutConstant = 0;
		CommTimeOuts.WriteTotalTimeoutMultiplier = 0;
		CommTimeOuts.WriteTotalTimeoutConstant = 5000;
		SetCommTimeouts( hcom, &CommTimeOuts );

		char szMessage[2] ;
	    unsigned char lpBuffer[10]  ;
	
		szMessage[0]=0x55;
		szMessage[1]=0xaa;
		DWORD dwBytesWritten;
		int i;
		for (i=0;i<2;i++){
	          WriteFile(hcom,szMessage,1,&dwBytesWritten,NULL);
		}
		DWORD dwBytesRead;
	    ReadFile(hcom,lpBuffer,6,&dwBytesRead,NULL);
	}

	number=0;
	SetTimer(1,500,NULL);

	
	draw();
}

void CCehuangyiView::OnStop() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	bfirst=false;
	CString strans;
	strans="Yes";
	GetDlgItem(IDC_YES+m_nanswer)->GetWindowText(strans);
	KillTimer(1);
	if (!m_pSet->IsEOF())
		m_pSet->MoveLast();
    UpdateData(false);
	if (m_survey->CanAppend()){
		m_survey->AddNew();
		m_survey->m_column1=m_name;
		m_survey->m_column2=m_wentiid;
		m_survey->m_column3=strans;
		m_survey->m_pzs=m_pSet->m___ID-number+1;
		m_survey->m_pze=m_pSet->m___ID;
		m_survey->m_hxe=m_pSet->m___ID;
		m_survey->m_xte=m_pSet->m___ID;
		m_survey->m_hxs=m_pSet->m___ID-number+1;
		m_survey->m_xts=m_pSet->m___ID-number+1;
	    
		if (m_survey->CanUpdate())
			m_survey->Update();
	    if (!m_survey->IsEOF())
			m_survey->MoveLast();
	    m_survey->Requery();
	    UpdateData(FALSE);
	}
	m_survey->Edit();
	UpdateData(false);
	if (m_survey->CanUpdate())//确定记录是否允许更新
		m_survey->Update();
	for (int w=0;w<160;w++){
		px[w]=py[w]=pyh[w]=pyx[w]=0;
		pt[w]=ph[w]=ppx[w]=CPoint(px[w],py[w]);
	}
	
	for (int sy=0;sy<4;sy++){
		lin[sy]=CPoint(0,0);
	}


}

void CCehuangyiView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	draw();
	char szg[1];
	szg[0]=0x00;
	unsigned char read[6];
	for (int i=0;i<6;i++)
	{
		read[i]=0;
	}
    DWORD dwBytesWritten;
    WriteFile(hcom,szg,1,&dwBytesWritten,NULL);
	DWORD dwBytesRead;
    ReadFile(hcom,read,6,&dwBytesRead,NULL);
	int k=((int)read[4]+(int)(0x0f&read[5])*256);
	pz=4096-((int)read[0]+(int)(0x0f&read[1])*256);
	xt= 4096-k;
	hx = ((int)read[2]+(int)(0x0f&read[3])*256+k/5-500);
	

	UpdateData(true);
	if (m_pSet->CanAppend()){
		m_pSet->AddNew();
	    m_pSet->m_hx=hx;
		m_pSet->m_pz=pz;
        m_pSet->m_xt=xt;

		if (m_pSet->CanUpdate())
			m_pSet->Update();
		if (!m_pSet->IsEOF())
			m_pSet->MoveLast();
	    m_pSet->Requery();
	    UpdateData(false);
	}
	m_pSet->Edit();
	UpdateData(true);
	if (m_pSet->CanUpdate())//确定记录是否允许更新
		m_pSet->Update();

	CClientDC dc(this);
	OnPrepareDC(&dc);
	
	CPen wPen;
	CPen *lpen;
	LOGPEN testPen;
	POINT Width={1}; //The POINT structure defines the x- and y- coordinates of a point. 

	testPen.lopnStyle =PS_SOLID;
	testPen.lopnWidth =Width;
	testPen.lopnColor =RGB(255,0,0);
	
	wPen.CreatePenIndirect (&testPen); //Initializes a pen that has the style, width, and color given in the structure pointed to by lpLogPen. 
    lpen=dc.SelectObject(&wPen);
    
	int num;
	int num1;
	int num2;

	if (number>150){
		num=150;
	    num1=150;
		num2=150;
		px[0]=3;
		for (int l=0;l<150;l++)
		{
			px[l+1]=px[l]+5;
			py[l]=py[l+1];
			pyh[l]=pyh[l+1];
			pyx[l]=pyx[l+1];
		}
		py[150]=(int)(pz*120/4096)+3;
		pyh[150]=(int)((hx+500)*120/5000)+124;
		pyx[150]=(int)(xt*120/4096)+2435;
		for (int m=0;m<151;m++)
		{
			pt[m]=CPoint(px[m],py[m]);
			ph[m]=CPoint(px[m],pyh[m]);
			ppx[m]=CPoint(px[m],pyx[m]);
		}
	}else{
		num=number;
		num1=number;
		num2=number;
		px[num]=753;
		py[num]=(int)(pz*120/4096)+3;
		pyh[num]=(int)((hx+500)*120/5000)+124;
		pyx[num]=(int)(xt*120/4096)+245;
		for (num ;num>0;num--){
			px[num-1]=px[num-1]-5;
		}
        for (int n=0;n<=num1;n++)
		{
			pt[n]=CPoint(px[n],py[n]);
			ph[n]=CPoint(px[n],pyh[n]);
			ppx[n]=CPoint(px[n],pyx[n]);
		}
	}
	int yu=(num1+1)%2;
    if (num1<5){
		dc.Polyline(pt,num1+1);
		dc.Polyline(ph,num1+1);
		dc.Polyline(ppx,num1+1);
	}else if (num1==5){
			dc.PolyBezier(pt,4);
			dc.PolyBezier(ph,4);
			dc.PolyBezier(ppx,4);
	}else{
		switch (yu){
		case 0:{
			int a=(num2-3)/2-1;
			for (int g=0;g<=a;g++){
				if (g==0){
					p[g][0]=pt[2*g];
					p[g][1]=pt[2*g+1];
					p[g][2]=pt[2*g+2];
					h[g][0]=ph[2*g];
					h[g][1]=ph[2*g+1];
					h[g][2]=ph[2*g+2];
					x[g][0]=ppx[2*g];
					x[g][1]=ppx[2*g+1];
					x[g][2]=ppx[2*g+2];
				}else if (g==a){
					p[g][1]=pt[2*g+1];
					p[g][2]=pt[2*g+2];
					p[g][3]=pt[2*g+3];
					h[g][1]=ph[2*g+1];
					h[g][2]=ph[2*g+2];
					h[g][3]=ph[2*g+3];
					x[g][1]=ppx[2*g+1];
					x[g][2]=ppx[2*g+2];
					x[g][3]=ppx[2*g+3];
				}else{
					p[g][1]=pt[2*g+1];
					p[g][2]=pt[2*g+2];
					h[g][1]=ph[2*g+1];
					h[g][2]=ph[2*g+2];
					x[g][1]=ppx[2*g+1];
					x[g][2]=ppx[2*g+2];
				}
			}
			for (int j=0;j<a;j++){
				p[j][3]=p[j+1][0]=CPoint((int)((px[2*j+2]+px[2*j+3])/2),(int)((py[2*j+2]+py[2*j+3])/2));
				h[j][3]=h[j+1][0]=CPoint((int)((px[2*j+2]+px[2*j+3])/2),(int)((pyh[2*j+2]+pyh[2*j+3])/2));
				x[j][3]=x[j+1][0]=CPoint((int)((px[2*j+2]+px[2*j+3])/2),(int)((pyx[2*j+2]+pyx[2*j+3])/2));
			}

			for (int c=0;c<=a;c++){
				for (int t=0;t<4;t++){
					lin[t]=p[c][t];
					lhx[t]=h[c][t];
					lxt[t]=x[c][t];
				}
				dc.PolyBezier(lin,4);
				dc.PolyBezier(lhx,4);
				dc.PolyBezier(lxt,4);
			}

			break;
			   }
		case 1:{
			int a=(num2-2)/2-1;
		    
			for (int i=0;i<=a;i++){
				if (i==0){
					p[i][0]=pt[2*i];
					p[i][1]=pt[2*i+1];
					p[i][2]=pt[2*i+2];
					h[i][0]=ph[2*i];
					h[i][1]=ph[2*i+1];
					h[i][2]=ph[2*i+2];
					x[i][0]=ppx[2*i];
					x[i][1]=ppx[2*i+1];
					x[i][2]=ppx[2*i+2];
				}else if (i==a){
					p[i][1]=pt[2*i+1];
					p[i][2]=CPoint((int)((px[2*i+1]+px[2*i+3])/2),(int)((py[2*i+1]+py[2*i+3])/2));
					p[i][3]=pt[2*i+3];
					h[i][1]=ph[2*i+1];
					h[i][2]=CPoint((int)((px[2*i+1]+px[2*i+3])/2),(int)((pyh[2*i+1]+pyh[2*i+3])/2));
					h[i][3]=ph[2*i+3];
					x[i][1]=ppx[2*i+1];
					x[i][2]=CPoint((int)((px[2*i+1]+px[2*i+3])/2),(int)((pyx[2*i+1]+pyx[2*i+3])/2));
					x[i][3]=ppx[2*i+3];
				}else{
					p[i][1]=pt[2*i+1];
					p[i][2]=pt[2*i+2];
					h[i][1]=ph[2*i+1];
					h[i][2]=ph[2*i+2];
					x[i][1]=ppx[2*i+1];
					x[i][2]=ppx[2*i+2];
				}
			}
			for (int d=0;d<a;d++){
				p[d][3]=p[d+1][0]=CPoint((int)((px[2*d+2]+px[2*d+3])/2),(int)((py[2*d+2]+py[2*d+3])/2));
				h[d][3]=h[d+1][0]=CPoint((int)((px[2*d+2]+px[2*d+3])/2),(int)((pyh[2*d+2]+pyh[2*d+3])/2));
				x[d][3]=x[d+1][0]=CPoint((int)((px[2*d+2]+px[2*d+3])/2),(int)((pyx[2*d+2]+pyx[2*d+3])/2));
			}

			
			for (int k=0;k<=a;k++){
				for (int o=0;o<4;o++){
					lin[o]=p[k][o];
					lhx[o]=h[k][o];
					lxt[o]=x[k][o];
				}
				dc.PolyBezier(lin,4);
				dc.PolyBezier(lhx,4);
				dc.PolyBezier(lxt,4);
			}

			break;
			   }
		}
	}
    number++;
	CRecordView::OnTimer(nIDEvent);
}

void CCehuangyiView::draw()
{
    CClientDC dc(this);
	OnPrepareDC(&dc);
	CBrush SolidBrush(RGB(255,255,255)); // choose the blue brush
	dc.SelectObject(&SolidBrush);
	dc.Rectangle (3,3 ,753,365);// draw a blue rectangle
	CPen wPen;
	CPen *lpen;
	LOGPEN testPen;
	POINT Width={2,1}; //The POINT structure defines the x- and y- coordinates of a point. 

 	testPen.lopnStyle =PS_DASH;
	testPen.lopnWidth =Width;
	testPen.lopnColor =RGB(0,0,0);
	
	wPen.CreatePenIndirect (&testPen); //Initializes a pen that has the style, width, and color given in the structure pointed to by lpLogPen. 
    lpen=dc.SelectObject(&wPen);
	dc.MoveTo(1,1); 
	dc.LineTo(1 ,367);
    dc.LineTo(755,367);
    dc.LineTo(755,1);
    dc.LineTo(1 ,1);
	dc.MoveTo(3,124);
	dc.LineTo(753,124);
	dc.MoveTo(3,245);
	dc.LineTo(753,245);

}

void CCehuangyiView::OnPeople() 
{
	// TODO: Add your control notification handler code here
	CPeople people;
	if (people.DoModal()==IDOK)
	{
		this->m_name =  people.m_people;
		this->UpdateData(false);
	}
}

void CCehuangyiView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	draw();
    bfirst=true;
}

void CCehuangyiView::OnQuestion() 
{
	// TODO: Add your control notification handler code here
	CWenti wenti;

	if (wenti.DoModal()==IDOK)
	{
		this->m_wentiid =  wenti.m_id;
		this->m_wenti	=	wenti.m_wenti;
		this->UpdateData(false);
	}
}

⌨️ 快捷键说明

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