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

📄 btmview.cpp

📁 一个很好的虚拟示波器!可一直接运行!他通过串口采集信号与系统单片机上的数据
💻 CPP
📖 第 1 页 / 共 2 页
字号:

void CBtmView::OnReleasedcaptureLeftslider(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	UpdateData();
 	theApp.m_nChannelLeft = m_NumLeftSlider;
//	m_ShowSwing.Format("%d",m_numAmpli);
	UpdateData(FALSE);
	*pResult = 0;
}

void CBtmView::OnReleasedcaptureRightslider(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	UpdateData();
 	theApp.m_nChannelRight = m_NumRightSlider;
	UpdateData(FALSE);
	*pResult = 0;
}


/*
HCURSOR CBtmView::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}*/

BOOL CBtmView::PreCreateWindow(CREATESTRUCT& cs) 
{
	// TODO: Add your specialized code here and/or call the base class
	// 创建自己的窗口类,窗口不设置光标,以便根据需要进行设置 
	if (cs.lpszClass == NULL)
		cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
	return CFormView::PreCreateWindow(cs);
}

void CBtmView::OnStartupBtn() 
{
	CMainFrame *m_pFram = (CMainFrame *)AfxGetMainWnd();
		
	if(theApp.m_bStartupStop)
	{
		m_bitmap1.DeleteObject();
		m_bitmap1.LoadBitmap(IDB_BITMAP_STARTUPBTN);
		m_StartupBtn.SetBitmap((HBITMAP)m_bitmap1);	
	}
	 if(!theApp.m_bStartupStop)
	{
		m_bitmap1.DeleteObject();
		m_bitmap1.LoadBitmap(IDB_BITMAP_STOPBTN);
		m_StartupBtn.SetBitmap((HBITMAP)m_bitmap1);
		::PostMessage(m_pFram->m_hWnd,UN_INITPORT_COM,0,0);
	}
	theApp.m_bStartupStop = !theApp.m_bStartupStop;
	
}

void CBtmView::OnStartBtn() 
{
	PostMessage(UM_SETBUTTON);
}

void CBtmView::OnTimer(UINT nIDEvent) 
{
	CMainFrame *m_pFram = (CMainFrame *)AfxGetMainWnd();
	CString m_strSendData = "";	

	theApp.flage = 0;
	theApp.m_mtstr = "";

	m_strSendData = "FE 15 " + theApp.m_strSampleSpeed + " FC";

	char data[1024];
	int len=Str2Hex(m_strSendData,data);

	if (theApp.m_bStartupStop && theApp.m_bStartupStop)
	{
		m_pFram->m_SerialPort.WriteToPort(data,len);
	}
	
	CFormView::OnTimer(nIDEvent);
}

//将一个字符串作为十六进制串转化为一个字节数组,字节间可用空格分隔,
//返回转换后的字节数组长度,同时字节数组长度自动设置。
int CBtmView::Str2Hex(CString str, char* data)
{
	int t,t1;
	int rlen=0,len=str.GetLength();
	
	for(int i=0;i<len;)
	{
		char l,h=str[i];
		if(h==' ')
		{
			i++;
			continue;
		}
		i++;
		if(i>=len)
			break;
		l=str[i];
		t=HexChar(h);
		t1=HexChar(l);
		if((t==16)||(t1==16))
			break;
		else 
			t=t*16+t1;
		i++;
		data[rlen]=(char)t;
		rlen++;
	}
	return rlen;

}


char CBtmView::HexChar(char c)
{
	if((c>='0')&&(c<='9'))
		return c-0x30;
	else if((c>='A')&&(c<='F'))
		return c-'A'+10;
	else if((c>='a')&&(c<='f'))
		return c-'a'+10;
	else 
		return 0x10;
}


void CBtmView::OnExitBtn() 
{
	// TODO: Add your control notification handler code here
	::PostMessage(theApp.m_hwndMainFrame,WM_CLOSE,0,0);
}


int CBtmView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;
	theApp.m_hWndBtmView = this->m_hWnd;
	myhFont = CreateFont((long)12,
		                  0,
						  0,
						  0,
						  400,
						  0,
						  0,
						  0,
						  GB2312_CHARSET,
						  OUT_DEFAULT_PRECIS,
						  CLIP_DEFAULT_PRECIS,
						  DEFAULT_QUALITY,
						  DEFAULT_PITCH|FF_DONTCARE,
						  "宋体");
	
	return 0;
}

void CBtmView::OnReleasedcaptureSampleRigor(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	theApp.m_mySample = m_NumSampleRigor;
	
	theApp.m_sSampleSpeed = (float)(m_SampleSlider.GetPos());
	theApp.m_sSampleSpeed = (int)(theApp.m_sSampleSpeed * theApp.m_mySample);
    SetMyTimer();
	
    theApp.m_strSampleSpeed.Format("%0X",(int)(theApp.m_sSampleSpeed));
	int m_strLength = theApp.m_strSampleSpeed.GetLength();
	for (int i=0; i<6-m_strLength;i++)
	{
		theApp.m_strSampleSpeed = "0" + theApp.m_strSampleSpeed;
	}
    theApp.m_strSampleSpeed.Insert(2," ");
	theApp.m_strSampleSpeed.Insert(5," ");

	*pResult = 0;
}


void CBtmView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData();
	theApp.m_mySample = m_NumSampleRigor;
	
	// 移动波形(上下移动)
	theApp.m_nChannelLeft = (int)((float)(m_LeftSlider.GetPos()))*5;
	theApp.m_nChannelRight = (int)((float)(m_RightSelider.GetPos()))*5;
	 
    // CH1调整幅度
	theApp.m_fVoleteVal1 = ((float)(m_rscSlider2.GetPos()))/10;
    theApp.m_strVoleteVal1.Format("%.1f",theApp.m_fVoleteVal1);
	theApp.m_strVoleteVal1 = theApp.m_strVoleteVal1 + "伏/格";
	m_rscSlider2.SetText("幅度");
	theApp.m_strVolete1 = theApp.m_strVoleteVal1;

	// CH2调整幅度
	theApp.m_fVoleteVal2 = ((float)(m_VolCH2Slider.GetPos()))/10;
    theApp.m_strVoleteVal2.Format("%.1f",theApp.m_fVoleteVal2);
	theApp.m_strVoleteVal2 = theApp.m_strVoleteVal2 + "伏/格";
	m_VolCH2Slider.SetText("幅度");
	theApp.m_strVolete2 = theApp.m_strVoleteVal2;

	//调整采样率
	theApp.m_sSampleSpeed = (int)((float)(m_SampleSlider.GetPos()) * theApp.m_mySample);
	SetMyTimer();
    theApp.m_strSampleSpeed.Format("%0X",(int)(theApp.m_sSampleSpeed));
	int m_strLength = theApp.m_strSampleSpeed.GetLength();
	for (int i=0; i<6-m_strLength;i++)
	{
		theApp.m_strSampleSpeed = "0" + theApp.m_strSampleSpeed;
	}
    theApp.m_strSampleSpeed.Insert(2," ");
	theApp.m_strSampleSpeed.Insert(5," ");

	//调整时基
	theApp.m_nTimer = m_TimerSlider.GetPos() * 10;
	CFormView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CBtmView::SetMyTimer()
{
	KillTimer(1);
	if (theApp.m_sSampleSpeed>=100000)
	{
		theApp.m_myNewTimer = 500;
	}
	else if (theApp.m_sSampleSpeed>=10000 && theApp.m_sSampleSpeed<100000)
	{
		theApp.m_myNewTimer = 600;
	}
	else if (theApp.m_sSampleSpeed>=1000 && theApp.m_sSampleSpeed<10000)
	{
		theApp.m_myNewTimer = 1000;
	}
	else
	{
		theApp.m_myNewTimer = 2000;
	}
	if (!theApp.m_bOpebFlage || !theApp.m_bPrintFlage)
	{
		SetTimer(1,theApp.m_myNewTimer,NULL);
		::SendMessage(theApp.m_Vsbqview, UM_WAVETIME, 0, 0);
	}
	
}

void CBtmView::OnMyKillTimer()
{
	CMainFrame *m_pFram = (CMainFrame *)AfxGetMainWnd();
	KillTimer(1);
	theApp.m_bStartPause = !theApp.m_bStartPause;
	m_pFram->m_bSaveFlage = TRUE;
}

void CBtmView::OnMySetTimer()
{
	CMainFrame *m_pFram = (CMainFrame *)AfxGetMainWnd();
	SetTimer(1,theApp.m_myNewTimer,NULL);
	::SendMessage(theApp.m_Vsbqview, UM_WAVETIME, 0, 0);
	theApp.m_bWavePlay = TRUE;
	theApp.m_bStartPause = !theApp.m_bStartPause;
	m_pFram->m_bSaveFlage = TRUE;
}


void CBtmView::OnMySetButton()
{
	CMainFrame *m_pFram = (CMainFrame *)AfxGetMainWnd();

	if(theApp.m_bStartPause)
	{
		m_bitmap2.DeleteObject();
		m_bitmap2.LoadBitmap(IDB_BITMAP_STARTBTN);
		m_StartBtn.SetBitmap((HBITMAP)m_bitmap2);	
		KillTimer(1);
	}
	 if(!theApp.m_bStartPause)
	{
		if(!(m_pFram->m_bSerialPortOpened) && !theApp.m_bPrintFlage)
		{
			MessageBox("串口没打开,请先按启动键打开串口!", "注意", MB_ICONEXCLAMATION);
			return;
		}
		m_bitmap2.DeleteObject();
		m_bitmap2.LoadBitmap(IDB_BITMAP_ZANTINGBTN);
		m_StartBtn.SetBitmap((HBITMAP)m_bitmap2);
		SetTimer(1,theApp.m_myNewTimer,NULL);
		::SendMessage(theApp.m_Vsbqview, UM_WAVETIME, 0, 0);
		theApp.m_bWavePlay = TRUE;
	}
	theApp.m_bStartPause = !theApp.m_bStartPause;
	m_pFram->m_bSaveFlage = TRUE;
}

HBRUSH CBtmView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
	
	if(pWnd->GetDlgCtrlID() == IDC_STATIC1 || pWnd->GetDlgCtrlID() == IDC_SAMPLE_RIGOR
		 || pWnd->GetDlgCtrlID() == IDC_STATIC1)
	{
		pDC->SetTextColor(RGB(0,0,0));
		pDC->SetBkMode(TRANSPARENT);
		return (HBRUSH)m_brBkgnd;
	}
	else
	{
		return hbr;
	}
	
}

void CBtmView::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
	


	CFormView::OnCaptureChanged(pWnd);
}

⌨️ 快捷键说明

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