【VC开源代码栏目提醒】:网学会员--在 VC开源代码编辑为广大网友搜集整理了:Ex16_4View.cpp绩等信息,祝愿广大网友取得需要的信息,参考学习。
// Ex16_4View.cpp : implementation of the CEx16_4View class
//
#include "stdafx.h"
#include "Ex16_4.h"
#include "Ex16_4Doc.h"
#include "Ex16_4View.h"
#include "ComsetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx16_4View
IMPLEMENT_DYNCREATE(CEx16_4View, CFormView)
BEGIN_MESSAGE_MAP(CEx16_4View, CFormView)
//{{AFX_MSG_MAP(CEx16_4View)
ON_COMMAND(ID_COMM_SET, OnCommSet)
ON_BN_CLICKED(IDC_BSEND, OnBsend)
//}}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()
// 串口
short m_ComPort[] = {1, 2, 3, 4};
// 波特率
int m_ComBaud[] = {1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600};
// 数据位
int m_ComDataBit[] = {7, 8};
// 停止位
CString m_ComStopBit[] = {"1", "1.5", "2"};
// 校验方式
CString m_ComParity[] = {"n", "o", "e"};
/////////////////////////////////////////////////////////////////////////////
// CEx16_4View construction/destruction
/////////////////////////////////////////
CEx16_4View::CEx16_4View()
: CFormView(CEx16_4View::IDD)
{
//{{AFX_DATA_INIT(CEx16_4View)
m_strSendText = _T("");
//}}AFX_DATA_INIT
// TODO: add construction code here
m_dwPoint = 0;
}
CEx16_4View::~CEx16_4View()
{
}
void CEx16_4View::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEx16_4View)
DDX_Control(pDX, IDC_LRECVTEXT, m_ctrlListRecvText);
DDX_Text(pDX, IDC_ESENDTEXT, m_strSendText);
DDX_Control(pDX, IDC_MSCOMM1, m_ctrlComm);
//}}AFX_DATA_MAP
}
BOOL CEx16_4View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CEx16_4View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CEx16_4View printing
BOOL CEx16_4View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx16_4View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx16_4View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CEx16_4View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CEx16_4View diagnostics
#ifdef _DEBUG
void CEx16_4View::AssertValid() const
{
CFormView::AssertValid();
}
void CEx16_4View::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CEx16_4Doc* CEx16_4View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx16_4Doc)));
return (CEx16_4Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx16_4View message handlers
BEGIN_EVENTSINK_MAP(CEx16_4View, CFormView)
//{{AFX_EVENTSINK_MAP(CEx16_4View)
ON_EVENT(CEx16_4View, IDC_MSCOMM1, 1 /* OnComm */, OnCommMscomm1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CEx16_4View::OnCommSet() // 配置串口参数
{
// TODO: Add your command handler code here
CComsetDlg dlg;
if (dlg.DoModal() == IDOK)
{
m_ctrlComm.SetCommPort(m_ComPort[dlg.m_nPort]); // 设置端口号
CString sSetting;
sSetting.Format("%d,%s,%d,%s", m_ComBaud[dlg.m_nBaud], m_ComParity[dlg.m_nCheck], m_ComDataBit[dlg.m_nDataBit], m_ComStopBit[dlg.m_nStopBit]);
m_ctrlComm.SetSettings(sSetting); // 配置串口
m_ctrlComm.SetPortOpen(TRUE); // 打开串口
}
}
void CEx16_4View::OnBsend()
{
// TODO: Add your control notification handler code here
if (m_ctrlComm.GetPortOpen() == FALSE)
return;
UpdateData(TRUE);
m_ctrlComm.SetOutput(COleVariant(m_strSendText + CString(13)));// 发送数据
m_strSendText = ""; // 清空发送数据
UpdateData(