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

📄 displaywindow.cpp

📁 USB接口虚拟示波器软件软件工程
💻 CPP
📖 第 1 页 / 共 3 页
字号:
      if(y0<=0) y0=0;
      else
        if(y0>disHight)
            y0=disHight-1;
  
     if(ad_data[i+1]>128)
        y1= s_y-hh[ad_data[i+1]]+h;
        else
          y1=s_y+s_y-hh[ad_data[i+1]];
            if(y1<=0) y1=0;
              else
                if(y1>disHight)
                   y1=disHight-1;
        GUI_DrawLine(i+xofst,y0+yofst,i+1+xofst,y1+yofst);        
  }

  */


void DisplayWindow::DrawLine()
{	
	CClientDC * pDC;
	pDC=new CClientDC(this);
	static int count;
	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 ();
	
	CPen  newPen(PS_SOLID,1,RGB(0,255,0));
 
	CPen *  oldPen=NULL;
	int s_y=leftSit;
	int s_x=0;	
	int h=DISHEIGHT/2;
	int width=DISWIDTH;
    int y,m_nTrigger=0;
    int point_x;
	oldPen=dc_Mem_B.SelectObject(&newPen);
	point_x=2;
//	if(addata[0]>128)
     y= s_y-ht[(int)addata[point_x++]];//+h;
 //       else
 //        y=s_y+s_y-ht[(int)addata[0]];
      if(y<=0)
		  y=0;
      else
        if(y>DISHEIGHT)
            y=DISHEIGHT-1;

    dc_Mem_B.MoveTo(s_x,y);

   
	for( int i=1;i<DISWIDTH;i++)
	{ 
	//	if(addata[i]>128)
	     y= s_y-ht[(int)addata[point_x++]];//+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);
	
	}
 //   dc_Mem_B.MoveTo(m_nTrigger,0);
//	dc_Mem_B.LineTo(m_nTrigger,DISHEIGHT);

//#define DISWIDTH 600
//#define DISHEIGHT 400
//#define XOFFSIZE  30
//#define YOFFSIZE  20
     

	count++;
	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 ();
	
	DisCymometer(&dc_Mem,300,10);
	DisVoltage(&dc_Mem,XOFFSIZE,YOFFSIZE-10,DISWIDTH,DISHEIGHT);
    DisTimeVlem(&dc_Mem,XOFFSIZE-15,YOFFSIZE,DISWIDTH,DISHEIGHT);
	DisLeftAxis(&dc_Mem,XOFFSIZE+DISWIDTH+2,YOFFSIZE+leftSit);
	
	
	if(disScaleLine)
     DisScaleLine(&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(oldBmp);
	dc_Mem.DeleteDC ();
	delete pDC;

}



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==3)
	{
	if(m_hCursor_V)
	::SetCursor(m_hCursor_V);
	SetCapture();
	}
	else
	if(Select==4||Select==5)
	{
	  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)
				     leftSit=DisRect.top-YOFFSIZE;
				   else
					     if(point.y>=DisRect.bottom)
					     leftSit=DisRect.bottom-YOFFSIZE;
						   else
							   leftSit=point.y-YOFFSIZE;
				   ReDrawSCreen();
				 break;
			  case 2:
				 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 3:
				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;
			 case 4:
		  
		  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 5:
		  
		  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;
		}
		
   }
   else
   {
	 if(point.x>lrect.left&&point.x<lrect.right&&point.y>lrect.top&&point.y<lrect.bottom)
	 {  Select=1;
          if (m_hCursor_V)
	     ::SetCursor(m_hCursor_V);
		}
     else
	if(disScaleLine)
	{ if(point.y>=UpScaleRect.top && point.y<=UpScaleRect.bottom)
		{  Select=2;
			  if (m_hCursor_V)
				::SetCursor(m_hCursor_V);
			}
	  else
		if(point.y>=DownScaleRect.top && point.y<=DownScaleRect.bottom)
		{  Select=3;
          if (m_hCursor_V)
	     ::SetCursor(m_hCursor_V);
		}
	  else
		if(point.x>=LeftScaleRect.left && point.x<=LeftScaleRect.right)
		{  Select=4;
			  if (m_hCursor_H)
					::SetCursor(m_hCursor_H);
			}
	  else
	  if(point.x>=RightScaleRect.left && point.x<=RightScaleRect.right)
		  {  Select=5;
			  if (m_hCursor_H)
				::SetCursor(m_hCursor_H);
			}
	}
   
   }
	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;
	*/
	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));
	pOldPen = pDC->SelectObject(&pen);
	 m_OldFont=pDC->SelectObject(m_font);
	if(x<40||x>800){delete pDC;return;}
    pDC->SetROP2 (R2_XORPEN);
	pDC->MoveTo(x,20);
    pDC->LineTo(x,hh-25-(4*h_st));
	int i=x-40;
	char mes[50];
	wsprintf(mes,"x=%d,Ldy=%d,Rdy=%d    ",i,
	data[1][i],data[3][i]);
     pDC->SetBkColor(RGB(0,0,0));
     pDC->SetTextColor(RGB(255,255,0));
     pDC->TextOut(ww/2+150,3,mes);
	 */
	//delete pDC;
}

void DisplayWindow::DisDinBiaoLine(CDC * pDC)
{	
}

void DisplayWindow::draw_line(CDC *pDC,int x, BOOL flag, char F)
{  
}



void DisplayWindow::ReDrawSCreen()
{  // if(pagedata_start==NULL)return;
    //  DrawLine(0,0);
DrawLine();

}


void DisplayWindow::OnRButtonDown(UINT nFlags, CPoint point) 
{
//	if (m_hCursor2)
//	::SetCursor(m_hCursor2);
//	mouse_XB=point.x;
//	SetCapture();

	CStatic::OnRButtonDown(nFlags, point);
}

void DisplayWindow::OnRButtonUp(UINT nFlags, CPoint point) 
{  // Play=0;
   // ReleaseCapture();	
	CStatic::OnRButtonUp(nFlags, point);
}

BOOL DisplayWindow::GetDinBiaoData(int x)
{
  		  return 1;
}

BOOL DisplayWindow::GetDYData()
{
  return 1;
}


BOOL DisplayWindow::DrwaDyRrand(int s)
{
	return 1;
}


void DisplayWindow::GetFenXinData()
{/*            CClientDC * pDC;
	        pDC=new CClientDC(this);
			
			delete pDC;
*/
}

BOOL DisplayWindow::GetADdata(HANDLE hDevice)
{ 


		
		return false;

/*
	float v;
    float ft=(float)(rand()%100);
	for(int i=0;i<1024;i++)
		{v=0.3*sin(2*PI*i/ft);
	     if(v>=0)
			ADdata[i]=128+BYTE(v*128);
			 else			
			 ADdata[i]=fabsf(v)*128;
		}

	return true;
*/


}

void DisplayWindow::GetBackToBmp()
{
	if(firstdiswindow)
	{CClientDC * pDC;
	pDC=new CClientDC(this);
	CDC dc_Mem;
    CBitmap * oldBmp = NULL;
	dc_Mem.CreateCompatibleDC(pDC);
	oldScreen_Bitmap.CreateCompatibleBitmap(pDC,ww,hh);
	oldBmp=dc_Mem.SelectObject(&oldScreen_Bitmap);
    dc_Mem.BitBlt(0,0,ww,hh,pDC,0,0,SRCCOPY); //  将原屏幕图象(oldScreen_Bitmap)
	dc_Mem.SelectObject (oldBmp);
	dc_Mem.DeleteDC();
	firstdiswindow=0;
	 delete pDC;
	}
}

void DisplayWindow::StartAD()
{   
	
/*	Caiyang=true;
  
	char DeviceName[50] = "Ezusb-0";  

	if(hUsbInDevice==NULL)
	{
	if(UsbOpenDriver (&hUsbInDevice, DeviceName) != TRUE) 
   { MessageBox( "无效设备,请重试!");
	 return ;
	}else
	SetTimer(1,10,NULL);
	}
*/
}

void DisplayWindow::PauseAD()
{
  // Caiyang=false;
}

void DisplayWindow::StopAD()
{
	
   //  KillTimer(1);
//	 CloseHandle (hUsbInDevice);
}

void DisplayWindow::OnTimer(UINT nIDEvent) 
{	

}

int DisplayWindow::Trigger()
{
   WORD  a=512;
	int m_nTriggerCH1=0;
		/* CH1 Tigger */
		for(int i = 1;i <= 1024;i++) 
		{
			if (m_nTriggerType == 0)
			{
			//	if(pDoc->m_nTriggerFormat == 1)
				//	a =ADdata[i-1];	// Edge Triggered
				/* trigger POS to NEG */
				if (addata[i] >= a && addata[i-1] < a)
				{
					m_nTriggerCH1 = i;
					
					/* Disable trigger for scroll mode */
				//	if (pApp->m_nSampleMode == 0) m_nTriggerCH1 = 0; // disbale trigger

				
					break;
				}

			}
			else
			{
			//	if(pDoc->m_nTriggerFormat == 1)

⌨️ 快捷键说明

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