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

📄 adwaveview.cpp

📁 AD 数据采集卡基本的采集界面
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		PointXY[3]=CPoint(PointXY[0].x,point.y );
		PointXY[4]=PointXY[0];
		
		dc.Polyline (PointXY,5);
		dc.SelectObject(oldPen);
		pen.DeleteObject();
		dc.SetROP2(nMode);*/

		pen.CreatePen(PS_SOLID ,1,RGB(255,255,255));
		oldPen=dc.SelectObject(&pen);
		nMode=dc.SetROP2(R2_XORPEN);
		dc.MoveTo(m_oldPoint.x,0);//消除上一次画的线
		dc.LineTo(m_oldPoint.x,ClientRect.Height());
		m_oldPoint=point;
		dc.MoveTo(point.x,0);
		dc.LineTo(point.x,ClientRect.Height());
		dc.SelectObject(oldPen);
		pen.DeleteObject();
		dc.SetROP2(nMode);
		
//------------------------------------------------------------------------

		CEdit* pFreqEdit=(CEdit*)(pShow->m_wndShowStatus1).GetDlgItem(IDC_EDIT_MeasureFreq); 
		int SubstValue;
		EndX = point.x;
		SubstValue = abs(StartX-EndX);
		str.Format("%7.2f", 1000000/(SubstValue*PerTime));
		pFreqEdit->SetWindowText(str);
	}

	CScrollView::OnMouseMove(nFlags, point);
}



void CADWaveView::OnSize(UINT nType, int cx, int cy) 
{
	CScrollView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	GetClientRect(&ClientRect);	 
	PerY=ClientRect.Height()/ChannelCount; 
	middle1=(float)((((m_ScreenVolume)/VOLT_RANGE)*LSB_COUNT)/(PerY-5));//每像素对应的码值    

}


void CADWaveView::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 
{
	// TODO: Add your message handler code here and/or call default
	
	CScrollView::OnNcCalcSize(bCalcValidRects, lpncsp);

	lpncsp->rgrc[0].left += m_ScaleV_Width; // 将视图客户区向右移,在左边留出非客户区,以供绘制左侧纵向刻度
	lpncsp->rgrc[0].top	+= m_ScaleH_Width; // 将视图客户区向下移,在上边留出非客户区,以供绘制上侧横向刻度

		//lpncsp->rgrc[0].right -= m_ScaleV_Width;
		//lpncsp->rgrc[0].bottom -= m_ScaleH_Width;
}

void CADWaveView::OnNcPaint() 
{
	CScrollView::OnNcPaint();
	// TODO: Add your message handler code here
	CWindowDC dc(this);	

	switch(ADPara.ChannelCount  )
	{
	case 1:
		DrawRulerV(&dc,m_ScaleV_Width);
		break;
	case 2:
	case 3:
		DrawRulerTwoChannel(&dc,m_ScaleV_Width,ADPara.ChannelCount );
		break;
	default:
		DrawRulerThreeChannel(&dc,m_ScaleV_Width,ADPara.ChannelCount );
		break;
	}
	// Do not call CScrollView::OnNcPaint() for painting messages
	DrawRulerH(&dc, m_ScaleH_Width);
}
void CADWaveView::DrawRulerVEX()
{
	CWindowDC dc(this);
	switch(ADPara.ChannelCount )
	{
		case 0:
		case 1:
			DrawRulerV(&dc,m_ScaleV_Width);
			break;
		case 2:
		case 3:
			DrawRulerTwoChannel(&dc,m_ScaleV_Width,ADPara.ChannelCount );
			break;
		default:
			DrawRulerThreeChannel(&dc,m_ScaleV_Width,ADPara.ChannelCount );
			break;
	}
}
void CADWaveView::DrawRulerHEx()
{

	CWindowDC dc(this);	
	DrawRulerH(&dc, m_ScaleH_Width);
}

void CADWaveView::DrawRulerH(CDC *pDC, int Height)
{
	CRect ClientRect;
	GetClientRect(&ClientRect);
	int ScrollBarH_Height = 50;
	int Width = ClientRect.right + ScrollBarH_Height;
	CRect Rect(m_ScaleV_Width, 0, Width, Height);
	CBrush brBorder;

	brBorder.CreateSolidBrush(GetSysColor(COLOR_SCROLLBAR));
	CBrush br(RGB(128, 128, 128));
	pDC->SelectObject(&br);
	pDC->Rectangle(Rect);
	pDC->FrameRect(&Rect,&brBorder);
	CPen Pen, *OldPen;
	Pen.CreatePen(PS_SOLID,1,RGB(223,223,223));

	pDC->SetBkMode(TRANSPARENT);
	OldPen = pDC->SelectObject(&Pen);
	int x;

	CString str;
	CFont Font, *OldFont;
	Font.CreateFont (14, 0, 0, 0, 300, // 其中900是方向角度
                       FALSE, FALSE, 0, DEFAULT_CHARSET,//ANSI_CHARSET,
                       OUT_DEFAULT_PRECIS, 
                       CLIP_DEFAULT_PRECIS,
                       DEFAULT_QUALITY, 
                       DEFAULT_PITCH|FF_SWISS, "Arial") ;

	OldFont=pDC->SelectObject(&Font);
	pDC->SetTextColor(RGB(128,255,255));
	x=Rect.left;
	str.Format("%duS", 0);
	pDC->TextOut(x+2, Rect.top+2, str);

	float PerTime=(float)(1000000.0/ADPara.Frequency);  // 单位时间
	int Index=0;
	x=Rect.left;
	for(Index=0; Index<Width; Index+=10)
	{
		if((Index%100==0))
		{
			pDC->MoveTo(x, 6);
			pDC->LineTo(x, Height-1);
			str.Format("%duS", (int)(Index*PerTime));
			pDC->TextOut(x+2, Rect.top+2, str);
		}
		else
		{
			pDC->MoveTo(x, 14);
			pDC->LineTo(x, Height-1);
		}
		x+=10;
	}
	pDC->SelectObject(OldFont);
	pDC->SelectObject(OldPen);

}



void CADWaveView::DrawRulerV(CDC *pDC, int Width)
{
	CRect ClientRect;
	GetClientRect(&ClientRect);
	int ScrollBarV_Height = 30;
	int Height = ClientRect.Height() + ScrollBarV_Height;
	CRect Rect(0, 0, Width, Height);
	CBrush brBorder;

	Height = ClientRect.Height();

	brBorder.CreateSolidBrush(GetSysColor(COLOR_SCROLLBAR));
	CBrush br(RGB(128, 128, 128));
	pDC->SelectObject(&br);
	pDC->Rectangle(Rect);//画矩形(刻度的底色)
	pDC->FrameRect(&Rect,&brBorder);
	CPen Pen, *OldPen;
	Pen.CreatePen(PS_SOLID,1,RGB(223,223,223));
	//刻度颜色句柄

	pDC->SetBkMode(TRANSPARENT);//设置背景模式
	OldPen=pDC->SelectObject(&Pen);
	int y, CenterY=Height/2;

	int VoltBottom=-5;
	int VoltTop=+5;
	int VoltRange=VoltTop-VoltBottom;//刻度量程设置
	int Index, Index1, PerY=Height/(VoltRange*10);
	CString str;
	CFont Font, *OldFont;
	Font.CreateFont (14, 0, 900, 0, 300, // 其中900是方向角度
                       FALSE, FALSE, 0, DEFAULT_CHARSET,//ANSI_CHARSET,
                       OUT_DEFAULT_PRECIS, 
                       CLIP_DEFAULT_PRECIS,
                       DEFAULT_QUALITY, 
                       DEFAULT_PITCH|FF_SWISS, "Arial") ;
  
	OldFont=pDC->SelectObject(&Font);
	pDC->SetTextColor(RGB(128,255,255));

	y=CenterY+m_ScaleH_Width;
	for(Index=0; Index<=VoltTop; Index++)
	{
		str.Format("%dV", Index);
		pDC->TextOut(Rect.left+4, y-2, str);
		pDC->MoveTo(10, y);//画刻度1和10 
		pDC->LineTo(Width-2, y);
		y-=PerY;
		for(Index1=0; Index1<=8; Index1++)
		{
			if(Index1==4)
			{
				pDC->MoveTo(15, y);
				pDC->LineTo(Width-2, y);			
			}
			{
				pDC->MoveTo(Width-10, y);
				pDC->LineTo(Width-2, y);
			}
			y-=PerY;
		}
	}

	y=CenterY+m_ScaleH_Width;
	for(Index=0; Index<=VoltTop; Index++)
	{
		if(Index!=0)
		{
			str.Format("-%dV", Index);
			pDC->TextOut(Rect.left+4, y-2, str);
		}
		pDC->MoveTo(10, y);
		pDC->LineTo(Width-2, y);
		y+=PerY;
		for(Index1=0; Index1<=8; Index1++)
		{
			if(Index1==4)
			{
				pDC->MoveTo(15, y);
				pDC->LineTo(Width-2, y);			
			}
			{
				pDC->MoveTo(Width-10, y);
				pDC->LineTo(Width-2, y);
			}
			y+=PerY;
		}
	}	
	pDC->SelectObject(OldFont);
	pDC->SelectObject(OldPen);
}
void CADWaveView::DrawRulerThreeChannel(CDC *pDC, int Width,int Channel)
{
	CRect ClientRect;
	GetClientRect(&ClientRect);
	//GetWindowRect(&ClientRect);
	//ClientRect.bottom /=Channel;//平均显示各个通道的刻度
	int ScrollBarV_Height = 30;
	int nTopLineY,nBottomLineY;
	int Height = ClientRect.Height() + ScrollBarV_Height;
	int tmpHeight = ClientRect.Height()/Channel;
	CRect Rect;
	CBrush Brush;

	Rect.top=Rect.left=0;
	Rect.bottom = ClientRect.bottom +ScrollBarV_Height;
	Rect.right = Width;	
	Brush.CreateSolidBrush(RGB(128,128,128));
	pDC->FillRect(Rect,&Brush);
	Brush.DeleteObject ();
	CString str;
	for(int i=0;i<Channel;i++)
	{
		nTopLineY = Rect.top = (tmpHeight*i)+m_ScaleH_Width;
		nBottomLineY =Rect.bottom = (tmpHeight*(i+1))+m_ScaleH_Width;
		Rect.left = 0;
		Rect.right = Width;
		Brush.CreateSolidBrush(pColor[i]);
		pDC->FillRect(Rect,&Brush);
		Brush.DeleteObject ();
		str.Format("%d",i);
		pDC->SetBkColor(pColor[i]);
		pDC->TextOut(2,nTopLineY+(nBottomLineY-nTopLineY)/3,str);
		
		pDC->MoveTo(0,nTopLineY);
		pDC->LineTo(ScrollBarV_Height,nTopLineY);
		pDC->MoveTo(0,nBottomLineY);
		pDC->LineTo(ScrollBarV_Height,nBottomLineY);
	}
	
}
void CADWaveView::DrawRulerTwoChannel(CDC *pDC, int Width,int Channel)
{
	CRect ClientRect;
	GetClientRect(&ClientRect);
	int ScrollBarV_Height = 30;
	int Height = ClientRect.Height() + ScrollBarV_Height;
	CRect Rect(0, 0, Width, Height);
	CBrush brBorder;
	Height=ClientRect.Height ()/Channel;

	brBorder.CreateSolidBrush(GetSysColor(COLOR_SCROLLBAR));
	CBrush br(RGB(128, 128, 128));
	pDC->SelectObject(&br);

	pDC->Rectangle(Rect);//画矩形(刻度的底色)
	pDC->FrameRect(&Rect,&brBorder);
	CPen Pen, *OldPen;
	Pen.CreatePen(PS_SOLID,1,RGB(223,223,223));
	//刻度颜色句柄

	pDC->SetBkMode(TRANSPARENT);//设置背景模式
	OldPen=pDC->SelectObject(&Pen);
	int y, CenterY=Height/2;

	int VoltBottom=-5;
	int VoltTop=+5;
	int VoltRange=VoltTop-VoltBottom;//刻度量程设置
	int Index,  PerY=(Height/2)/(5);
	CString str;
	CFont Font, *OldFont;
	Font.CreateFont (14, 0, 900, 0, 300, // 其中900是方向角度
                       FALSE, FALSE, 0, DEFAULT_CHARSET,//ANSI_CHARSET,
                       OUT_DEFAULT_PRECIS, 
                       CLIP_DEFAULT_PRECIS,
                       DEFAULT_QUALITY, 
                       DEFAULT_PITCH|FF_SWISS, "Arial") ;
  
	OldFont=pDC->SelectObject(&Font);
	pDC->SetTextColor(RGB(128,255,255));
	for(int num=0;num<Channel;num++)//给每个通道画刻度
	{
		y=CenterY+m_ScaleH_Width+Height*num;//CenterY*2;
		for(Index=0; Index<=VoltTop; Index++)
		{		

			{
				str.Format("%dV", Index);
				pDC->TextOut(Rect.left+4, y-2, str);
				pDC->MoveTo(10, y);//画刻度
				pDC->LineTo(Width-2, y);
				y-=(PerY);
				pDC->MoveTo(15, y);//画刻度
				pDC->LineTo(Width-2, y);
				y-=(PerY);
				Index++;
				if(Index==VoltTop)
				{
					y+=(PerY);
					str.Format("%dV", Index);
					pDC->TextOut(Rect.left+4, y+8, str);
				}
				
			}
		}
		
		y=CenterY+m_ScaleH_Width+Height*num;//CenterY*2;
		for(Index=0; Index<=VoltTop; Index++)
		{
			{
				if(Index!=0)
				{
					str.Format("-%dV", Index);
					pDC->TextOut(Rect.left+4, y-2, str);
				}
				pDC->MoveTo(10, y);//画刻度
				pDC->LineTo(Width-2, y);
				y+=(PerY);
				pDC->MoveTo(15, y);//画刻度
				pDC->LineTo(Width-2, y);
				y+=(PerY);
				Index++;
				if(Index==VoltTop)
				{
					y-=(PerY);
					str.Format("-%dV", Index);
					pDC->TextOut(Rect.left+4, y-2, str);
					
				}					
			}
		}	
	}
	pDC->SelectObject(OldFont);
	pDC->SelectObject(OldPen);
	
}

⌨️ 快捷键说明

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