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

📄 displaywindow.cpp

📁 最新的USB示波器源码?可直接编译生成可执行程序,需要硬件支持
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            if(y1<=0) y1=0;
              else
                if(y1>disHight)
                   y1=disHight-1;
        GUI_DrawLine(i+xofst,y0+yofst,i+1+xofst,y1+yofst);        
  }

	int h=DISHEIGHT/2;

   // float v;
    for(i=0;i<128;i++)
    {   v=(float)(i/128.0);
     	ht[i]=h*v-h; 
    
     }
	for(;i<256;i++)
	{   v=(float)(i/128.0);
     	ht[i]=h-h*v; 
    
     }
  */

#define ARROW_W 15
#define ARROW_H 6
void DisplayWindow::DrawLine()
{	int i;
	CClientDC * pDC;
	pDC=new CClientDC(this);
	static int count,count1;
	int left_sit,right_sit;
	CString mes;
	CDC dc_Mem_B;
    CBitmap Black_Bitmap;
	CBitmap * oldBmp_B= NULL;
	dc_Mem_B.CreateCompatibleDC(pDC);
    Black_Bitmap.CreateCompatibleBitmap(pDC,DISWIDTH,DISWIDTH);
	//Black_Bitmap.CreateCompatibleBitmap(pDC,rcClip.Width (),rcClip.Height ());
	oldBmp_B=dc_Mem_B.SelectObject(&Black_Bitmap);
	
	CDC dc_Mem_temp;
    CBitmap * oldBmp_temp = NULL;
	dc_Mem_temp.CreateCompatibleDC(pDC);
	oldBmp_temp=dc_Mem_temp.SelectObject(&oldScreen_Bitmap);
	
	dc_Mem_B.BitBlt(0,0,DISWIDTH,DISWIDTH,&dc_Mem_temp,0,0,SRCCOPY); 
	
	dc_Mem_temp.SelectObject(oldBmp_temp);
	dc_Mem_temp.DeleteDC ();
	int xi;

	CPen  greenPen(PS_SOLID,1,RGB(0,255,0));
    CPen  yelloPen(PS_SOLID,1,RGB(255,255,0));
	CPen  chensePen(PS_SOLID,1,RGB(255,200,0));
	CPen  chensePen_dot (PS_DOT, 1,  RGB(255,200,0));
	
	CPen *  oldPen=NULL;

	if(!time_base.format)
		DrawYTgraph(&dc_Mem_B);
	  else
	  {	DrawXYgraph(&dc_Mem_B);   
	  }
/*
	int s_y;
	int s_x=0;	
	int h=DISHEIGHT/2;
	int width=DISWIDTH;
    int y,m_nTrigger=0;
    int xi=time_base.memory_offset;

    if(cha_param.display )
	{s_y=cha_param.y_offset ;
      oldPen=dc_Mem_B.SelectObject(&greenPen);
       y= s_y-ht[(int)cha_addata[xi]];//+h;

	if(y<=0)
		  y=0;
      else
        if(y>DISHEIGHT)
            y=DISHEIGHT-1;

    dc_Mem_B.MoveTo(s_x,y);
     xi++;
   
	for( i=1;i<DISWIDTH;i+=time_base.x_step)
	{ 
	//	if(addata[i]>128)
	     y= s_y-ht[(int)cha_addata[xi++]];//+h;
     //   else
	//	 y=s_y+s_y-ht[(int)addata[i]];
         //y=s_y+h*(v);
		  if(y<=0)
		  y=0;
		  else
		if(y>=DISHEIGHT)
		   y=DISHEIGHT-1;

	 	dc_Mem_B.LineTo(s_x+i,y);
	//	dc_Mem_B.MoveTo(s_x+i,y);
	}

	}
	
	xi=time_base.memory_offset ;
	if(chb_param.display )
	{s_y=chb_param.y_offset ;
    oldPen=dc_Mem_B.SelectObject(&yelloPen);
    y= s_y-ht[(int)chb_addata[xi]];//+h;

	if(y<=0)
		  y=0;
      else
        if(y>DISHEIGHT)
            y=DISHEIGHT-1;

    dc_Mem_B.MoveTo(s_x,y);
     xi++;
   
	for( int i=1;i<DISWIDTH;i+=time_base.x_step)
	{ 
	//	if(addata[i]>128)
	     y= s_y-ht[(int)chb_addata[xi++]];//+h;
     //   else
	//	 y=s_y+s_y-ht[(int)addata[i]];
         //y=s_y+h*(v);
		  if(y<=0)
		  y=0;
		  else
		if(y>=DISHEIGHT)
		   y=DISHEIGHT-1;

	 	dc_Mem_B.LineTo(s_x+i,y);
	}
	}

  */
	CDC dc_Mem;
    CBitmap Dis_Bitmap;
	CBitmap * oldBmp= NULL;
	dc_Mem.CreateCompatibleDC(pDC);
    Dis_Bitmap.CreateCompatibleBitmap(pDC,rcClip.Width (),rcClip.Height ());
	oldBmp=dc_Mem.SelectObject(&Dis_Bitmap);
	
	dc_Mem.BitBlt(XOFFSIZE,YOFFSIZE,DISWIDTH,DISWIDTH,&dc_Mem_B,0,0,SRCCOPY); 
	dc_Mem_B.SelectObject(oldPen);
	dc_Mem_B.SelectObject(oldBmp_B);
	dc_Mem_B.DeleteDC ();
   // if(isRecord)
//	{
    dc_Mem.SetTextColor (RGB(0,255,0));
	dc_Mem.SetBkMode (TRANSPARENT);
	mes.Format ("FPS=%d",fps);// acquire.counter++);
	dc_Mem.TextOut (XOFFSIZE,YOFFSIZE-15,mes);
//	}
    if(display.freq_on_ch1)
	{
	//count1++;
	//if(count1>2)
	//{count1=0;
   /*  GetFreq(0,&left_sit,&right_sit);
   	if(right_sit>left_sit){
      oldPen=dc_Mem.SelectObject (&chensePen_dot);
   	dc_Mem.MoveTo (XOFFSIZE+left_sit-time_base.memory_offset,YOFFSIZE+50);
   	dc_Mem.LineTo (XOFFSIZE+left_sit-time_base.memory_offset,YOFFSIZE+DISHEIGHT-50);
   	dc_Mem.MoveTo (XOFFSIZE+right_sit-time_base.memory_offset,YOFFSIZE+50);
   	dc_Mem.LineTo (XOFFSIZE+right_sit-time_base.memory_offset,YOFFSIZE+DISHEIGHT-50);
      freq=GetFreqString(left_sit,right_sit);
    
   		}
   	else
   	  freq=_T("XXXX");
   		}*/
   	//	 dc_Mem.SetTextColor (RGB(0,255,0));
   	// dc_Mem.SetBkMode (TRANSPARENT);
   	// dc_Mem.TextOut (XOFFSIZE,YOFFSIZE+DISHEIGHT+15,freq);
   
	
	  DisplayZhiFuGrap(&dc_Mem);
//	}
	
	}
	if(isDrawOther)
	{isDrawOther=false;
	if(cha_param.display ){
    dc_Mem.SetTextColor (RGB(0,255,0));
	dc_Mem.SetBkMode (TRANSPARENT);
	dc_Mem.TextOut (XOFFSIZE+DISWIDTH+ARROW_H+4,YOFFSIZE+cha_param.y_offset-ARROW_H-2,"A");
    oldPen=dc_Mem.SelectObject (&greenPen);
	dc_Mem.MoveTo (XOFFSIZE+DISWIDTH,YOFFSIZE+cha_param.y_offset);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H,YOFFSIZE+cha_param.y_offset-ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H+ARROW_W,YOFFSIZE+cha_param.y_offset-ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H+ARROW_W,YOFFSIZE+cha_param.y_offset+ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H,YOFFSIZE+cha_param.y_offset+ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH,YOFFSIZE+cha_param.y_offset);

	cha_arrow_rect.left=XOFFSIZE+DISWIDTH;
    cha_arrow_rect.right=XOFFSIZE+DISWIDTH+ARROW_H+ARROW_W;
    cha_arrow_rect.top=YOFFSIZE+cha_param.y_offset-ARROW_H;
    cha_arrow_rect.bottom=YOFFSIZE+cha_param.y_offset+ARROW_H;


	}
	else
	{
	cha_arrow_rect.left=0;
    cha_arrow_rect.right=0;
    cha_arrow_rect.top=0;
    cha_arrow_rect.bottom=0;
	}

   	if(chb_param.display ){
    dc_Mem.SetTextColor (RGB(255,255,0));
	dc_Mem.SetBkMode (TRANSPARENT);
	dc_Mem.TextOut (XOFFSIZE+DISWIDTH+ARROW_H+4,YOFFSIZE+chb_param.y_offset-ARROW_H-2,"B");
    oldPen=dc_Mem.SelectObject (&yelloPen);
	dc_Mem.MoveTo (XOFFSIZE+DISWIDTH,YOFFSIZE+chb_param.y_offset);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H,YOFFSIZE+chb_param.y_offset-ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H+ARROW_W,YOFFSIZE+chb_param.y_offset-ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H+ARROW_W,YOFFSIZE+chb_param.y_offset+ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH+ARROW_H,YOFFSIZE+chb_param.y_offset+ARROW_H);
    dc_Mem.LineTo (XOFFSIZE+DISWIDTH,YOFFSIZE+chb_param.y_offset);
	chb_arrow_rect.left=XOFFSIZE+DISWIDTH;
    chb_arrow_rect.right=XOFFSIZE+DISWIDTH+ARROW_H+ARROW_W;
    chb_arrow_rect.top=YOFFSIZE+chb_param.y_offset-ARROW_H;
    chb_arrow_rect.bottom=YOFFSIZE+chb_param.y_offset+ARROW_H;
	}
	else
	{
	chb_arrow_rect.left=0;
    chb_arrow_rect.right=0;
    chb_arrow_rect.top=0;
    chb_arrow_rect.bottom=0;
	}
    

        i=((128-trigger.level)*250)/128;

	if(trigger.source ==0||trigger.source ==2)
	   i+=cha_param.y_offset;
	else
       	if(trigger.source ==1)
			i+=chb_param.y_offset;
	    else
			i=0;
		if(i<0)
			i=0;
			if(i>DISHEIGHT)
				i=DISHEIGHT;

	oldPen=dc_Mem.SelectObject (&chensePen);
	dc_Mem.MoveTo (XOFFSIZE,YOFFSIZE+i );
    dc_Mem.LineTo (XOFFSIZE-ARROW_H,YOFFSIZE+i-ARROW_H);
    dc_Mem.LineTo (XOFFSIZE-ARROW_H-ARROW_W,YOFFSIZE+i-ARROW_H);
	dc_Mem.LineTo (XOFFSIZE-ARROW_H-ARROW_W,YOFFSIZE+i+ARROW_H);
	dc_Mem.LineTo (XOFFSIZE-ARROW_H,YOFFSIZE+i+ARROW_H);
	dc_Mem.LineTo (XOFFSIZE,YOFFSIZE+i);
    dc_Mem.SetTextColor (RGB(255,200,0));
	dc_Mem.TextOut (XOFFSIZE-ARROW_H-ARROW_W+4,YOFFSIZE+i-ARROW_H,"T");


	if(trigger.display)
	{
     if(trigger.disp_counter++>30)
        trigger.display=false;

	
      oldPen=dc_Mem.SelectObject (&chensePen_dot);
	dc_Mem.LineTo (XOFFSIZE+DISWIDTH,YOFFSIZE+i);

	}
	dc_Mem.SetBkMode (OPAQUE);
	 xi=time_base.trigger_offset-time_base.memory_offset;
	 if(xi>0&&xi<DISWIDTH){
     dc_Mem.SetBkColor(RGB(255,200,0));
	 dc_Mem.SetTextColor (RGB(0,0,0));
	 dc_Mem.TextOut (XOFFSIZE+xi-4,YOFFSIZE+i-10," T ");
	 }
	dc_Mem.SetBkMode (TRANSPARENT);
//	DisVoltage(&dc_Mem,XOFFSIZE,YOFFSIZE,DISWIDTH,DISHEIGHT);
//	DisLeftAxis(&dc_Mem,XOFFSIZE+DISWIDTH+2,YOFFSIZE+leftSit);
	DisTrig_sit(&dc_Mem,-12);

	if(scaleline_mode>0)
     DisScaleLine(&dc_Mem,XOFFSIZE,YOFFSIZE,DISWIDTH,DISHEIGHT);

//	 DisTimeVlem(&dc_Mem,XOFFSIZE,YOFFSIZE,DISWIDTH,DISHEIGHT);
	}
	 
	 //DisTopAxis(&dc_Mem, XOFFSIZE+topSit, YOFFSIZE);
	pDC->BitBlt(0,0,rcClip.Width (),rcClip.Height (),&dc_Mem,0,0,SRCCOPY); 
    dc_Mem.SelectObject(oldPen);
	dc_Mem.SelectObject(oldBmp);
	dc_Mem.DeleteDC ();
	delete pDC;
	
//	if(Caiyang)
//	{ ord[0]='R';
//	  SendCommandToUSB(ord,VR_USRCMD); 
//	}

}



BOOL DisplayWindow::DeletePage()
{ 
	return 0;
}
//如果步长是1,则显示的DATA[0]-DATA[2]-DATA[4]-----DATA[1716]-DATA[1718]-DATA[1520]
//如果步长是2,则显示的DATA[0]-DATA[1]-DATA[3]-----DATA[858]-DATA[859]-DATA[760]

void DisplayWindow::OnLButtonDown(UINT nFlags, CPoint point) 
{
	//if(point.x>lrect.top&&point.x<lrect.right&&point.y>lrect.top&&point.y<lrect.bottom)
	if(Select==1||Select==2||Select==5||Select==6)
	{
//	if(m_hCursor_V)
	::SetCursor(m_hCursor_V);
	SetCapture();
	}
	else
	if(Select==3||Select==4)
	{
	 // if(m_hCursor_H)
    	::SetCursor(m_hCursor_H);
		SetCapture();
	}
		
CStatic::OnLButtonDown(nFlags, point);

}
//#define XOFFSIZE  30
//#define YOFFSIZE  20
/*
   LeftScaleRect.left=x+LeftScaleSit-topbm.bmWidth/2;
   LeftScaleRect.top=y-topbm.bmHeight;
   LeftScaleRect.right=trect.left+topbm.bmWidth;
   LeftScaleRect.bottom=trect.top+topbm.bmHeight;

   RightScaleRect.left=x+RightScaleSit-topbm.bmWidth/2;
   RightScaleRect.top=y-topbm.bmHeight;
   RightScaleRect.right=trect.left+topbm.bmWidth;
   RightScaleRect.bottom=trect.top+topbm.bmHeight;
	
   UpScaleRect.left=x+w;
   UpScaleRect.top=y+UpScaleSit-leftscalebm.bmHeight/2;
   UpScaleRect.right=UpScaleRect.left+leftscalebm.bmWidth;
   UpScaleRect.bottom=UpScaleRect.top+leftscalebm.bmHeight;

   DownScaleRect.left=x+w;
   DownScaleRect.top=y+DownScaleSit-leftscalebm.bmHeight/2;
   DownScaleRect.right=UpScaleRect.left+leftscalebm.bmWidth;
   DownScaleRect.bottom=UpScaleRect.top+leftscalebm.bmHeight;
*/

void DisplayWindow::OnMouseMove(UINT nFlags, CPoint point) 
{
//int LeftScaleSit,RightScaleSit,UpScaleSit,DownScaleSit;

	if(nFlags&MK_LBUTTON)//mouse left press and move
	{
			switch(Select)
			{ case 1:
				 if(point.y<=DisRect.top)
				     cha_param.y_offset=DisRect.top-YOFFSIZE;
				   else
					     if(point.y>=DisRect.bottom)
					      cha_param.y_offset=DisRect.bottom-YOFFSIZE;
						   else
							    cha_param.y_offset=point.y-YOFFSIZE;
				   ReDrawSCreen();
				 break;

                case 2:
				 if(point.y<=DisRect.top)
				      chb_param.y_offset=DisRect.top-YOFFSIZE;
				   else
					     if(point.y>=DisRect.bottom)
					     chb_param.y_offset=DisRect.bottom-YOFFSIZE;
						   else
							   chb_param.y_offset=point.y-YOFFSIZE;
				   ReDrawSCreen();
				 break;

	 case 3:
		  
		  if(point.x<=DisRect.left)
			  LeftScaleSit=DisRect.left-XOFFSIZE;
		  else
			  if(point.x>=DisRect.right)
				  LeftScaleSit=DisRect.right-XOFFSIZE;
			  else
			 LeftScaleSit=point.x-XOFFSIZE;
			ReDrawSCreen();
		
	   break;
	  case 4:
		  
		  if(point.x<=DisRect.left)
			  RightScaleSit=DisRect.left-XOFFSIZE;
		  else
			  if(point.x>=DisRect.right)
				  RightScaleSit=DisRect.right-XOFFSIZE;
			  else
			 RightScaleSit=point.x-XOFFSIZE;
			ReDrawSCreen();
	   break;

			  case 5:
				 if(point.y<=DisRect.top)
			       UpScaleSit=DisRect.top-YOFFSIZE;
				     else
				        if(point.y>=DisRect.bottom)
					      UpScaleSit=DisRect.bottom-YOFFSIZE;
							  else
								 UpScaleSit=point.y-YOFFSIZE;
					 ReDrawSCreen();
		 
				 break;
			 case 6:
				if(point.y<=DisRect.top)
					DownScaleSit=DisRect.top-YOFFSIZE;
					else
						if(point.y>=DisRect.bottom)
							 DownScaleSit=DisRect.bottom-YOFFSIZE;
							else
								DownScaleSit=point.y-YOFFSIZE;
								   ReDrawSCreen();
					break;
		
		}
		
   }
   else
   { if(point.x>cha_arrow_rect.left && point.x<cha_arrow_rect.right && point.y> cha_arrow_rect.top && point.y< cha_arrow_rect.bottom)
	 {  Select=1;
          if (m_hCursor_V)
	      ::SetCursor(m_hCursor_V);
		}
	 else
		if(point.x>chb_arrow_rect.left && point.x<chb_arrow_rect.right && point.y> chb_arrow_rect.top && point.y< chb_arrow_rect.bottom)
		 {  Select=2;
			   if (m_hCursor_V)
				   ::SetCursor(m_hCursor_V);
				}
	  else
	if(scaleline_mode>0)
	{// LeftScaleSit,RightScaleSit,UpScaleSit,DownScaleSit;
		switch(scaleline_mode)
		{
		case 1:  // ||
			if(point.x>=LeftScaleSit+XOFFSIZE-3 && point.x<=LeftScaleSit+XOFFSIZE+3)
				{  Select=3;
				//  if (m_hCursor_H)
					::SetCursor(m_hCursor_H);
				}else	
             	if(point.x>=RightScaleSit+XOFFSIZE-3 && point.x<=RightScaleSit+XOFFSIZE+3)
				{  Select=4;
				///  if (m_hCursor_H)
					::SetCursor(m_hCursor_H);
				}	else
					Select=0;

			break;
		case 2:  // =

               if(point.y>=UpScaleSit+YOFFSIZE-3 && point.y<=UpScaleSit+YOFFSIZE+3)
				{  Select=5;
				  //if (m_hCursor_V)
					::SetCursor(m_hCursor_V);
				}
			   else
             	if(point.y>=DownScaleSit+YOFFSIZE-3 && point.y<=DownScaleSit+YOFFSIZE+3)
				{  Select=6;
				 // if (m_hCursor_V)
					::SetCursor(m_hCursor_V);
				}else
						Select=0;

			break;
		case 3:  // |
				if(point.x>=LeftScaleSit+XOFFSIZE-3 && point.x<=LeftScaleSit+XOFFSIZE+3)
				{  Select=3;
				 // if (m_hCursor_H)
					::SetCursor(m_hCursor_H);
				}	else
						Select=0;

			break;
		case 4:  // -

			if(point.y>=UpScaleSit+YOFFSIZE-3 && point.y<=UpScaleSit+YOFFSIZE+3)
				{  Select=5;
			//  if (m_hCursor_H)
					::SetCursor(m_hCursor_V);
				}else
						Select=0;
			break;
		}
	}
	else
	
		Select=0;
 
   }
	CStatic::OnMouseMove(nFlags, point);
}

void DisplayWindow::OnLButtonUp(UINT nFlags, CPoint point) 
{	
/*if(SelectT)
	{mouse_x=point.x+9;
    DrawViewLine(mouse_x);
	SelectT=0;}
	F_B=F_H=F_S=F_I=F_D=F_E=0;
	F_b=F_h=F_s=F_i=F_d=F_e=0;
	*/Select=0;
	SelectT=0;
	ReleaseCapture();
	

	CStatic::OnLButtonUp(nFlags, point);
}


void DisplayWindow::DrawViewLine(int x)
{ 
/*   CClientDC * pDC;
	pDC=new CClientDC(this);
    CPen* pOldPen;
	CPen pen (PS_SOLID,1,RGB(255,0,0));

⌨️ 快捷键说明

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