📄 dlgcomset.cpp
字号:
// DlgComset.cpp : implementation file
//
#include "stdafx.h"
#include "maintain.h"
#include "DlgComset.h"
#include "SerialComm.h"
#include "maintainDoc.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgComset property page
IMPLEMENT_DYNCREATE(CDlgComset, CPropertyPage)
CDlgComset::CDlgComset() : CPropertyPage(CDlgComset::IDD)
{
//{{AFX_DATA_INIT(CDlgComset)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CDlgComset::CDlgComset(LPSerialLineInfo pInfo) : CPropertyPage(CDlgComset::IDD)
{
ZeroMemory(&m_SerialLineInfo,sizeof(SerialLineInfo));
m_SerialLineInfo.m_nComNo = pInfo->m_nComNo;
m_SerialLineInfo.m_nComBaut = pInfo->m_nComBaut;
m_SerialLineInfo.m_nDataBit = pInfo->m_nDataBit;
m_SerialLineInfo.m_nStopBit = pInfo->m_nStopBit;
m_SerialLineInfo.m_nParity = pInfo->m_nParity;
m_SerialLineInfo.m_FlowControl = pInfo->m_FlowControl;
}
CDlgComset::~CDlgComset()
{
}
void CDlgComset::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgComset)
DDX_Control(pDX, IDC_COMBO_PARITY, m_parity);
DDX_Control(pDX, IDC_COMBO_STOP, m_stop);
DDX_Control(pDX, IDC_COMBO_DATA, m_data);
DDX_Control(pDX, IDC_COMBO_COMNO, m_comno);
DDX_Control(pDX, IDC_COMBO_BAUD, m_baud);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgComset, CPropertyPage)
//{{AFX_MSG_MAP(CDlgComset)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgComset message handlers
BOOL CDlgComset::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
/* CMaintainDoc *m_doc = NULL;
m_doc = ((CMainFrame*)AfxGetMainWnd())->GetDoc();
if (!m_doc)
return false;
ZeroMemory(&m_SerialLineInfo,sizeof(SerialLineInfo));
memcpy(&m_SerialLineInfo,m_doc->GetSerialLineInfo(),sizeof(SerialLineInfo));
m_comno.SetCurSel(m_SerialLineInfo.m_nComNo-1);
m_baud.SetCurSel(m_SerialLineInfo.m_nComBaut);
m_data.SetCurSel(m_SerialLineInfo.m_nDataBit);
(m_SerialLineInfo.m_nStopBit == STOP_1)?m_stop.SetCurSel(0):m_stop.SetCurSel(1);;
switch(m_SerialLineInfo.m_nParity)
{
case P_NONE:
m_parity.SetCurSel(0);
break;
case P_EVEN:
m_parity.SetCurSel(1);
break;
case P_ODD:
m_parity.SetCurSel(2);
break;
}
*/
m_comno.SetCurSel(m_SerialLineInfo.m_nComNo-1);
m_baud.SetCurSel(m_SerialLineInfo.m_nComBaut);
m_data.SetCurSel(m_SerialLineInfo.m_nDataBit);
(m_SerialLineInfo.m_nStopBit == STOP_1)?m_stop.SetCurSel(0):m_stop.SetCurSel(1);;
switch(m_SerialLineInfo.m_nParity)
{
case P_NONE:
m_parity.SetCurSel(0);
break;
case P_EVEN:
m_parity.SetCurSel(1);
break;
case P_ODD:
m_parity.SetCurSel(2);
break;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgComset::OnOK()
{
// TODO: Add extra validation here
/* ZeroMemory(&m_SerialLineInfo,sizeof(SerialLineInfo));
m_SerialLineInfo.m_nComNo = m_comno.GetCurSel()+1;
m_SerialLineInfo.m_nComBaut = m_baud.GetCurSel();
m_SerialLineInfo.m_nDataBit = m_data.GetCurSel();
m_SerialLineInfo.m_nStopBit = m_stop.GetCurSel();
switch(m_parity.GetCurSel())
{
case 0://无校验
m_SerialLineInfo.m_nParity = P_NONE;
break;
case 1://偶校验
m_SerialLineInfo.m_nParity = P_EVEN;
break;
case 2://奇校验
m_SerialLineInfo.m_nParity = P_ODD;
break;
default:
m_SerialLineInfo.m_nParity = P_NONE;
break;
}
CMaintainDoc *m_doc = NULL;
m_doc = ((CMainFrame*)AfxGetMainWnd())->GetDoc();
if (m_doc)
m_doc->SetSerialLineInfo(&m_SerialLineInfo);
*/
if(m_comno.GetCurSel() == -1)
{
MessageBox(_T("请指定串口号!"),"提示",MB_OK|MB_ICONINFORMATION);
return ;
}
if(m_baud.GetCurSel() == -1)
{
MessageBox(_T("请指定波特率!"),"提示",MB_OK|MB_ICONINFORMATION);
return ;
}
if(m_data.GetCurSel() == -1)
{
MessageBox(_T("请指定数据位!"),"提示",MB_OK|MB_ICONINFORMATION);
return ;
}
if(m_stop.GetCurSel() == -1)
{
MessageBox(_T("请指定停止位!"),"提示",MB_OK|MB_ICONINFORMATION);
return ;
}
if(m_parity.GetCurSel() == -1)
{
MessageBox(_T("请指定校验类型!"),"提示",MB_OK|MB_ICONINFORMATION);
return ;
}
ZeroMemory(&m_SerialLineInfo,sizeof(SerialLineInfo));
m_SerialLineInfo.m_nComNo = m_comno.GetCurSel()+1;
m_SerialLineInfo.m_nComBaut = m_baud.GetCurSel();
m_SerialLineInfo.m_nDataBit = m_data.GetCurSel();
m_SerialLineInfo.m_nStopBit = m_stop.GetCurSel();
switch(m_parity.GetCurSel())
{
case 0://无校验
m_SerialLineInfo.m_nParity = P_NONE;
break;
case 1://偶校验
m_SerialLineInfo.m_nParity = P_EVEN;
break;
case 2://奇校验
m_SerialLineInfo.m_nParity = P_ODD;
break;
default:
m_SerialLineInfo.m_nParity = P_NONE;
break;
}
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -