📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "Vsbq.h"
#include "ComSetDlg.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CVsbqApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_SIZE()
ON_MESSAGE(UN_SENDDATA, SendData) /////////////////////////
ON_MESSAGE(UN_READ_COM, ReadData) /////////////////////////
ON_MESSAGE(UN_INITPORT_COM, OnInitPort) /////////////////////////
ON_MESSAGE(UN_CLOSEPORT_COM, OnClosePort) /////////////////////////
ON_WM_TIMER()
ON_COMMAND(ID_WAVE_SAVE, OnWaveSave)
ON_COMMAND(IDM_COMSET, OnComset)
ON_COMMAND(ID_CURSORX, OnCursorx)
ON_COMMAND(ID_CURSORY, OnCursory)
ON_UPDATE_COMMAND_UI(ID_CURSORX, OnUpdateCursorx)
ON_UPDATE_COMMAND_UI(ID_CURSORY, OnUpdateCursory)
ON_COMMAND(IDM_MODECH1, OnModech1)
ON_UPDATE_COMMAND_UI(IDM_MODECH1, OnUpdateModech1)
ON_COMMAND(IDM_MODECH2, OnModech2)
ON_UPDATE_COMMAND_UI(IDM_MODECH2, OnUpdateModech2)
ON_COMMAND(MODEANDCH, OnMODEANDCH)
ON_UPDATE_COMMAND_UI(MODEANDCH, OnUpdateMODEANDCH)
ON_COMMAND(ID_MENUITEM32781, OnMenuitem32781)
ON_UPDATE_COMMAND_UI(ID_MENUITEM32781, OnUpdateMenuitem32781)
ON_COMMAND(IDM_HELP, OnHelp)
ON_COMMAND(IDM_SPRINGCH1, OnSpringch1)
ON_COMMAND(IDM_SPRINGCH2, OnSpringch2)
ON_UPDATE_COMMAND_UI(IDM_SPRINGCH1, OnUpdateSpringch1)
ON_UPDATE_COMMAND_UI(IDM_SPRINGCH2, OnUpdateSpringch2)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
IDS_THISTIMER,
IDS_TIMER,
ID_INDICATOR_NUM,
IDS_COMPANYMANE,
};
////////////////////////、/////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_bSendNumFlage = true; // 默认为发送的数字
m_bSerialPortOpened = FALSE; // 开始时串口没打开
m_strReceiveMsg = "";
m_strSendMsg = "";
m_hCom = 1;
m_nBaudRate = 115200;
m_parity = 'N';
m_bCommflag = false;
m_strTimer = "";
saveflage = FALSE;
m_bSaveFlage = FALSE;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
/* if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}*/
// this->SetActiveView()
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
/* m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);*/
theApp.m_hwndMainFrame = this->m_hWnd;
SetTimer(1,1000,NULL);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
int xSize = ::GetSystemMetrics(SM_CXSCREEN);
int ySize = ::GetSystemMetrics(SM_CYSCREEN);
cs.cx = xSize*5/6;
cs.cy = ySize*6/7;
cs.x = (xSize-cs.cx)/2;
cs.y = (ySize-cs.cy)/4;
cs.style &= ~WS_MAXIMIZEBOX ;
cs.style &= ~WS_THICKFRAME ;
cs.style &= ~FWS_ADDTOTITLE;
cs.lpszName = "THDSOCI--1000数字存储示波器";
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base classCBtmView
m_wndSplitter1.CreateStatic(this,2,1);
m_wndSplitter1.CreateView(1,0,RUNTIME_CLASS(CBtmView),CSize(0,200),pContext);
m_wndSplitter2.CreateStatic(&m_wndSplitter1,1,2,WS_CHILD |WS_VISIBLE,m_wndSplitter1.IdFromRowCol(0,0));
m_wndSplitter2.CreateView(0,1,RUNTIME_CLASS(CLftView),CSize(100,100),pContext);
m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CVsbqView),CSize(0,0),pContext);
m_wndSplitter1.SetColumnInfo(0,180,255);
m_wndSplitter2.SetColumnInfo(0,684,684);
m_wndSplitter2.SetRowInfo(0,100,100);
m_wndSplitter1.SetRowInfo(0,425,425);
// m_wndSplitter1.RecalcLayout();
m_wndSplitter1.SetActivePane(0,0,NULL);
return TRUE;
}
void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CFrameWnd::OnLButtonDown(nFlags, point);
}
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CFrameWnd::OnSize(nType, cx, cy);
}
LONG CMainFrame::ReadData(WPARAM ch, LPARAM port)
{
CString aaaa = "";
theApp.m_aryReceDat[theApp.m_count++] = ch;
aaaa.Format("%3d",theApp.m_aryReceDat[theApp.m_count-1]);
theApp.m_mtstr = theApp.m_mtstr + aaaa + ", ";
if (theApp.flage%20 == 0)
{
theApp.m_mtstr += "\r\n";
}
if (theApp.flage>4000 && saveflage)
{
SaveWave(theApp.m_mtstr);
theApp.m_mtstr = "";
theApp.flage = 0;
saveflage = FALSE;
}
theApp.flage ++;
return 0;
}
void CMainFrame::SendData()
{
}
//初始化串口
void CMainFrame::OnInitPort()
{
OnClosePort();
m_SerialPort.InitVlue();
CString strStatus;
if (m_SerialPort.InitPort(this, m_hCom, m_nBaudRate,m_parity,8,1,EV_RXFLAG | EV_RXCHAR,512))
{
m_SerialPort.StartMonitoring();
m_bSerialPortOpened = TRUE;
}
else
{
m_bSerialPortOpened = FALSE;
}
}
// 关闭串口
void CMainFrame::OnClosePort()
{
m_SerialPort.ClosePort();//关闭串口
Sleep(10);
m_bSerialPortOpened = FALSE;
}
// 波形文件保存
void CMainFrame::SaveWave(CString str)
{
CStdioFile file;
CFileDialog fileDlg(FALSE);
fileDlg.m_ofn.lpstrTitle = "波形文件保存";
fileDlg.m_ofn.lpstrFilter = "wave Files(*.wav)\0*.wav\0All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt = "wav";
if (IDOK == fileDlg.DoModal())
{
if( !file.Open(fileDlg.GetFileName(), CFile::modeCreate
| CFile::modeWrite | CFile::typeBinary ))
{
AfxMessageBox("创建文件失败!");
return;
}
file.WriteString(str);
file.Close();
str = "您的文件已成功保存在:\n\n"+fileDlg.GetPathName()+"目录下!";
MessageBox(str);
}
}
// 波形文件打开
void CMainFrame::OnFileOpen()
{
int i = 0;
int m_nStrLength = 0;
CString m_strWaveFile = "";
CString m_strOpenFile = "";
CStdioFile file;
theApp.m_bOpebFlage = TRUE;
::PostMessage(theApp.m_hWndBtmView, UM_MYKILLTIMER, 0, 0);
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle = "波形文件打开";
fileDlg.m_ofn.lpstrFilter = "wave Files(*.wav)\0*.wav\0All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrDefExt = "wav";
if (IDOK == fileDlg.DoModal())
{
file.Open(fileDlg.GetFileName(),CFile::modeRead);
while(file.ReadString(m_strWaveFile))
{
m_nStrLength = m_strWaveFile.GetLength()/5;
for (i=0; i<m_nStrLength; i++)
{
m_strOpenFile = m_strWaveFile.Mid(i*5, 3);
int aaaa = atoi(m_strOpenFile);
theApp.m_aryReceDat[theApp.m_count++] = aaaa;
}
}
}
else
{
::PostMessage(theApp.m_hWndBtmView, UM_MYSETTIMER, 0, 0);
}
::PostMessage(theApp.m_hWndBtmView, UM_SETBUTTON, 0, 0);
theApp.m_bWavePlay = TRUE;
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CTime CurTime = CTime::GetCurrentTime();
m_strTimer.Format("%d:%d:%d",CurTime.GetHour(),CurTime.GetMinute(),CurTime.GetSecond());
m_wndStatusBar.SetPaneText(2, m_strTimer,TRUE);
CFrameWnd::OnTimer(nIDEvent);
}
// 波形保存菜单按钮
void CMainFrame::OnWaveSave()
{
// TODO: Add your command handler code here
if (!m_bSaveFlage)
{
MessageBox("您当前没有要保存的波形");
}
else
{
saveflage = TRUE;
}
}
void CMainFrame::OnComset()
{
// TODO: Add your command handler code here
CComSetDlg ComSetDlg;
ComSetDlg.DoModal();
}
void CMainFrame::OnCursorx()
{
theApp.m_bnoniusx == TRUE ? theApp.m_bnoniusx = FALSE : theApp.m_bnoniusx = TRUE;
}
void CMainFrame::OnCursory()
{
theApp.m_bnoniusy == TRUE ? theApp.m_bnoniusy = FALSE : theApp.m_bnoniusy = TRUE;
}
void CMainFrame::OnUpdateCursorx(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(theApp.m_bnoniusx);
}
void CMainFrame::OnUpdateCursory(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(theApp.m_bnoniusy);
}
// 示波器模式设置
void CMainFrame::OnModech1()
{
if(theApp.m_strModeApp == "CH2")
{
theApp.m_strModeApp = "CH1 CH2";
}
else if (theApp.m_strModeApp == "CH1")
{
theApp.m_strModeApp = "";
}
else if (theApp.m_strModeApp == "CH1 CH2")
{
theApp.m_strModeApp = "CH2";
}
else
{
theApp.m_strModeApp = "CH1";
}
}
void CMainFrame::OnUpdateModech1(CCmdUI* pCmdUI)
{
if (theApp.m_strModeApp == "CH1" || theApp.m_strModeApp == "CH1 CH2")
{
pCmdUI->SetCheck(TRUE);
}
else
{
pCmdUI->SetCheck(FALSE);
}
}
void CMainFrame::OnModech2()
{
if(theApp.m_strModeApp == "CH2")
{
theApp.m_strModeApp = "";
}
else if (theApp.m_strModeApp == "CH1")
{
theApp.m_strModeApp = "CH1 CH2";
}
else if (theApp == "CH1 CH2")
{
theApp.m_strModeApp = "CH1";
}
else
{
theApp.m_strModeApp = "CH2";
}
}
void CMainFrame::OnUpdateModech2(CCmdUI* pCmdUI)
{
if (theApp.m_strModeApp == "CH2" || theApp.m_strModeApp == "CH1 CH2")
{
pCmdUI->SetCheck(TRUE);
}
else
{
pCmdUI->SetCheck(FALSE);
}
}
void CMainFrame::OnMODEANDCH()
{
if(theApp.m_strModeApp == "CH1+CH2")
{
theApp.m_strModeApp = "";
}
else
{
theApp.m_strModeApp = "CH1+CH2";
}
}
void CMainFrame::OnUpdateMODEANDCH(CCmdUI* pCmdUI)
{
if (theApp.m_strModeApp == "CH1+CH2")
{
pCmdUI->SetCheck(TRUE);
}
else
{
pCmdUI->SetCheck(FALSE);
}
}
void CMainFrame::OnMenuitem32781()
{
if(theApp.m_strModeApp == "X-Y")
{
theApp.m_strModeApp = "";
}
else
{
theApp.m_strModeApp = "X-Y";
}
}
void CMainFrame::OnUpdateMenuitem32781(CCmdUI* pCmdUI)
{
if (theApp.m_strModeApp == "X-Y")
{
pCmdUI->SetCheck(TRUE);
}
else
{
pCmdUI->SetCheck(FALSE);
}
}
void CMainFrame::OnHelp()
{
}
//CH1通道同步触发设置
void CMainFrame::OnSpringch1()
{
theApp.m_bIsochronous1 = !theApp.m_bIsochronous1;
}
void CMainFrame::OnUpdateSpringch1(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(theApp.m_bIsochronous1);
}
//CH2通道同步触发设置
void CMainFrame::OnSpringch2()
{
theApp.m_bIsochronous2 = !theApp.m_bIsochronous2;
}
void CMainFrame::OnUpdateSpringch2(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(theApp.m_bIsochronous2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -