利用vc++编写的绘图界面如下图所示,关于画笔画刷以及颜色控制任何关于VC++程序开发的书籍中都能找到资料。
绘图函数程序如下:
CPaintDC dc(this); // device context for painting // TODO: 在此处添加消息处理程序代码 // 不为绘图消息调用CDialog::OnPaint() ADOConn m_ado; m_ado.OnnitADOConn(); _RecordsetPtr m_precord; CRect rect; GetClientRect(&rect); CBrush myBrush; myBrush.CreateSolidBrush(RGB(255, 255, 255));//或者myBrush.CreateHatchBrush(HS_CROSS, RGB(55, 0, 0)); dc.FillRect(&rect, &myBrush); CDC *p=this->GetDC(); CPen pen; pen.CreatePen(PS_SOLID,1.7,RGB(0,0,0)); ::SelectObject(p->GetSafeHdc(),pen); p->SetBkMode(TRANSPARENT); int left=40; int right=rect.right-47; int top=50; int bottom=rect.bottom-80; //画坐标轴直线 p->MoveTo(left,top); p->LineTo(left,bottom); p->LineTo(right,bottom); p->LineTo(right,top); p->LineTo(left,top); int tempX=(right-left)/10; CPen pen1; pen1.CreatePen(PS_DASHDOT,1.7,RGB(0,0,0)); ::SelectObject(p->GetSafeHdc(),pen1); double startFrc=0; double endFrec=0; CString sqlt="select * from CanShu where Type='X1'" ; m_precord=m_ado.GetRecordSet(_bstr_t(sqlt)); startFrc=m_precord->GetCollect("Value"); sqlt="select * from CanShu where Type='X2'" ; m_precord=m_ado.GetRecordSet(_bstr_t(sqlt)); endFrec=m_precord->GetCollect("Value"); double tempXFrec=(endFrec-startFrc)/10; for (int i=0;i<11;i++) { p->MoveTo(left+tempX*i,bottom); p->LineTo(left+tempX*i,top); double xlable=startFrc+i*tempXFrec; CString s; s.Format("%.2f",xlable); p->TextOut(left+i*tempX,bottom,s); } //CString sR; //sR.Format("%.2f",endFrec); //p->TextOut(left+10*tempX,bottom,sR); double topdb=0; double downdb=0; sqlt="select * from CanShu where Type='Y1'" ; m_precord=m_ado.GetRecordSet(_bstr_t(sqlt)); topdb=m_precord->GetCollect("Value");//最上面的电平值参考电平 sqlt="select * from CanShu where Type='Y2'" ; m_precord=m_ado.GetRecordSet(_bstr_t(sqlt)); downdb=m_precord->GetCollect("Value");//原点的电平值 double tempYdb=(topdb-downdb)/10; int tempY=(bottom-top)/10; for (int j=0;j<10;j++) { p->MoveTo(left,bottom-j*tempY); p->LineTo(right,bottom-j*tempY); if (j!=0) { CString s; s.Format("%.2f",downdb+j*tempYdb); p->TextOut(left+5,bottom-j*tempY,s); } } CString sT; sT.Format("%.2f",topdb); p->TextOut(left+5,bottom-10*tempY,sT); p->TextOut(left-30,bottom-10*tempY,"Ref"); CString span; span.Format("%.2f",endFrec-startFrc); p->TextOut(left+5*tempX,bottom+tempY/3,""); p->TextOut(left+5*tempX,bottom+tempY,"SPAN:0 HZ"); p->TextOut(left+10*tempX,bottom+tempY/3,"s"); p->TextOut(left,top-20,"dbm"); //取数据画图 CPen pen2; pen2.CreatePen(PS_SOLID,1.7,RGB(255,0,0)); ::SelectObject(p->GetSafeHdc(),pen2); CString sql="select * from data order by Frec asc" ; m_precord=m_ado.GetRecordSet(_bstr_t(sql)); int xData=0; int yData=0; double Frec=0; double Result=0; int flag=0; //p->MoveTo(left,bottom); while (m_ado.m_pRecordSet->adoEOF==0) { Frec=m_precord->GetCollect("Frec"); Result=m_precord->GetCollect("Result"); xData=(right-left)*(Frec-startFrc)/(endFrec-startFrc); yData=(bottom-top)*(Result-downdb)/(topdb-downdb); if (flag==0) { p->MoveTo(left+xData,bottom-yData); flag=1; } else { p->LineTo(left+xData,bottom-yData); } /*if (Frec==startFrc) { p->MoveTo(left+xData,bottom-yData); } else p->LineTo(left+xData,bottom-yData);*/ m_precord->MoveNext(); } m_ado.ExitConnect();