📄 复件 examviewview.cpp
字号:
// examviewView.cpp : implementation of the CExamviewView class
//
#include "stdafx.h"
#include "examview.h"
#include "examviewDoc.h"
#include "examviewView.h"
#include "ComSetSheet.h"
#include "ComSetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExamviewView
IMPLEMENT_DYNCREATE(CExamviewView, CFormView)
BEGIN_MESSAGE_MAP(CExamviewView, CFormView)
//{{AFX_MSG_MAP(CExamviewView)
ON_WM_CREATE()
ON_COMMAND(ID_FILE_EXPORT, OnFileExport)
ON_COMMAND(ID_FILE_IMPORT, OnFileImport)
ON_COMMAND(IDM_COM_SETUP, OnComSetup)
ON_COMMAND(IDM_COM_OPEN, OnComOpen)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExamviewView construction/destruction
CExamviewView::CExamviewView()
: CFormView(CExamviewView::IDD)
{
//{{AFX_DATA_INIT(CExamviewView)
m_bTune1 = FALSE;
m_bTune2 = FALSE;
m_bTune4 = FALSE;
m_bTune3 = FALSE;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CExamviewView::~CExamviewView()
{
}
void CExamviewView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExamviewView)
DDX_Control(pDX, IDC_MSCOMM1, m_MSComm);
DDX_Check(pDX, IDC_TUNE1, m_bTune1);
DDX_Check(pDX, IDC_TUNE2, m_bTune2);
DDX_Check(pDX, IDC_TUNE4, m_bTune4);
DDX_Check(pDX, IDC_TUNE3, m_bTune3);
//}}AFX_DATA_MAP
}
BOOL CExamviewView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CExamviewView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CExamviewView printing
BOOL CExamviewView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExamviewView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExamviewView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CExamviewView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CExamviewView diagnostics
#ifdef _DEBUG
void CExamviewView::AssertValid() const
{
CFormView::AssertValid();
}
void CExamviewView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CExamviewDoc* CExamviewView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExamviewDoc)));
return (CExamviewDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExamviewView message handlers
BEGIN_EVENTSINK_MAP(CExamviewView, CFormView)
//{{AFX_EVENTSINK_MAP(CExamviewView)
ON_EVENT(CExamviewView, IDC_MSCOMM1, 1 /* OnComm */, OnComm, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CExamviewView::OnComm()
{
// TODO: Add your control notification handler code here
}
int CExamviewView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_MSComm.Create(NULL,0,CRect(0,0,0,0),this,IDC_MSCOMM1);
m_MSComm.SetCommPort(1);
m_MSComm.SetInputMode(1);
m_MSComm.SetInBufferSize(1024);
m_MSComm.SetOutBufferSize(512);
m_MSComm.SetSettings("9600,n,8,1");
m_MSComm.SetRThreshold(1);
m_MSComm.SetInputLen(0);
if(!m_MSComm.GetPortOpen())
m_MSComm.SetPortOpen(TRUE);
else
MessageBox("打开串口出错");
m_MSComm.GetInput();
return 0;
}
void CExamviewView::OnFileExport()
{
// TODO: Add your command handler code here
CString ch="abcd";
CFileDialog fileDlg(FALSE);//FALSE为保存
fileDlg.m_ofn.lpstrTitle="导出数据";//标题
fileDlg.m_ofn.lpstrDefExt="xxl";//默认保存的文件类型
fileDlg.m_ofn.lpstrFilter="XXL Files(*.xxl)\0*.xxl\0All Files(*.*)\0*.*\0\0";//过滤
if(IDOK==fileDlg.DoModal())
{
CFile file(ch,CFile::modeCreate | CFile::modeWrite);
file.Write(ch,strlen(ch));
file.Close();//响应文件名的输出方式还有问题存在
}
}
void CExamviewView::OnFileImport()
{
// TODO: Add your command handler code here
CFileDialog fileDlg(TRUE);//FALSE为保存
fileDlg.m_ofn.lpstrTitle="导出数据";//标题
fileDlg.m_ofn.lpstrFilter="XXL Files(*.xxl)\0*.txt\0All Files(*.*)\0*.*\0\0";//过滤
if(IDOK==fileDlg.DoModal())
{
CString ch="abcd";
CFile file(ch,CFile::modeRead);
char *pBuf;
DWORD dwFileLen;
dwFileLen=file.GetLength();
pBuf=new char[dwFileLen+1];
pBuf[dwFileLen]=0;
file.Read(pBuf,dwFileLen);
file.Close();//响应文件名的输出方式还有问题存在
MessageBox(pBuf);
}
}
void CExamviewView::OnComSetup() //在此处实现端口设置参数的传递。但是参数的具体传递细节没有解决
{
// TODO: Add your command handler code here
UpdateData(TRUE);
CComSetSheet m_ComSetSheet("多路温度仪");//参数是指显示标题
//m_cBaud.GetCurSel()
if(IDOK==m_ComSetSheet.DoModal())
{
CString baud=m_ComSetSheet.m_ComSetDlg.m_sBaud;//属性表属性值的访问方式。得到的是CString类型
int index=m_ComSetSheet.m_ComSetDlg.m_cPort.GetCurSel();
// ((CComboBox*)GetDlgItem(IDC_PORT))->GetLBText(index,cc);
// index=CWnd::GetDlgItem(IDC_PORT)->GetCurSel();
// ((CComboBox*)GetDlgItem(IDC_PORT))->SetCurSel(1);
// index=((CComboBox*)GetDlgItem(IDC_PORT))->GetCurSel();
//index=m_Baud.GetCurSel();
}
// char index;
// index=GetDlgItem(IDC_PORT)->GetCurSel();
// port=atoi(index)+1;
// MessageBox(port);
}
void CExamviewView::OnComOpen()
{
// TODO: Add your command handler code here
if( !m_MSComm.GetPortOpen())
{
m_MSComm.SetPortOpen(TRUE);//打开串口
// SetDlgItemText(IDC_BUTTON1,"关闭串口");
}
else
{
m_MSComm.SetPortOpen(FALSE);
// SetDlgItemText(IDC_BUTTON1,"打开串口");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -