📄 commsettingsdlg.cpp
字号:
// From VC4.2 Sample VCTERM
// Modify by JHCC, 1997
// CommSettingsDlg.cpp : implementation of the CCommSettingsDlg class
#include "stdafx.h"
#include "JHHB.h"
#include "CommSettingsDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCommSettingsDlg dialog
// set up initial settings in dialog to mirror
// the current settings
CCommSettingsDlg::CCommSettingsDlg(CWnd* pParent)
: CDialog(CCommSettingsDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCommSettingsDlg)
m_bDTRDSR = FALSE;
m_bRTSCTS = FALSE;
m_bXONXOFF = FALSE;
//}}AFX_DATA_INIT
CString strCommSection;
strCommSection.LoadString(IDS_COMMSECTION);
CString strCommBaudRateItem;
strCommBaudRateItem.LoadString(IDS_COMMBAUDRATE);
int nBaudRate = ::AfxGetApp()->GetProfileInt(strCommSection, strCommBaudRateItem, DEFAULT_BUADRATE);
switch (nBaudRate)
{
case CBR_300:
m_baud = 0;
break;
case CBR_600:
m_baud = 1;
break;
case CBR_1200:
m_baud = 2;
break;
case CBR_2400:
m_baud = 3;
break;
case CBR_4800:
m_baud = 4;
break;
case CBR_9600:
m_baud = 5;
break;
default:
m_baud = 0; // 300
break;
}
CString strCommDataBitsItem;
strCommDataBitsItem.LoadString(IDS_COMMDATABITS);
int nDataBits = ::AfxGetApp()->GetProfileInt(strCommSection, strCommDataBitsItem, DEFAULT_DATABITS);
switch (nDataBits)
{
case 7:
m_databits = 0;
break;
case 8:
m_databits = 1;
break;
default:
m_databits = 1; // 8
break;
}
CString strCommStopBitsItem;
strCommStopBitsItem.LoadString(IDS_COMMSTOPBITS);
int nStopBits = ::AfxGetApp()->GetProfileInt(strCommSection, strCommStopBitsItem, DEFAULT_STOPBITS);
switch (nStopBits)
{
case ONESTOPBIT:
m_stopbits = 0;
break;
case TWOSTOPBITS:
m_stopbits = 1;
break;
default:
m_stopbits = 0; // 1 stop bits
}
CString strCommParityItem;
strCommParityItem.LoadString(IDS_COMMPARITY);
int nParity = ::AfxGetApp()->GetProfileInt(strCommSection, strCommParityItem, DEFAULT_PARITY);
switch (nParity)
{
case NOPARITY:
m_parity = 0;
break;
case ODDPARITY:
m_parity = 1;
break;
case EVENPARITY:
m_parity = 2;
break;
default:
m_parity = 0; // NONE
}
CString strCommPortItem;
strCommPortItem.LoadString(IDS_COMMPORT);
int nCommPort = ::AfxGetApp()->GetProfileInt(strCommSection, strCommPortItem, DEFAULT_COMMPORT);
switch (nCommPort)
{
case 1:
m_comport = 0;
break;
case 2:
m_comport = 1;
break;
case 3:
m_comport = 2;
break;
case 4:
m_comport = 3;
break;
default:
m_comport = 0; // COMM1
break;
}
CString strCommFlowCtrlItem;
strCommFlowCtrlItem.LoadString(IDS_COMMFLOWCTRL);
int nFlowCtrl = ::AfxGetApp()->GetProfileInt(strCommSection, strCommFlowCtrlItem, DEFAULT_FLOWCTRLS);
if (nFlowCtrl & PCF_DTRDSR)
m_bDTRDSR = TRUE;
if (nFlowCtrl & PCF_RTSCTS)
m_bRTSCTS = TRUE;
if (nFlowCtrl & PCF_XONXOFF)
m_bXONXOFF = TRUE;
}
void CCommSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCommSettingsDlg)
DDX_Radio(pDX, IDC_BAUD1, m_baud);
DDX_Radio(pDX, IDC_COM1, m_comport);
DDX_Radio(pDX, IDC_DATABITS1, m_databits);
DDX_Radio(pDX, IDC_PARITY1, m_parity);
DDX_Radio(pDX, IDC_STOPBITS1, m_stopbits);
DDX_Check(pDX, IDC_DTR_DSR, m_bDTRDSR);
DDX_Check(pDX, IDC_RTS_CTS, m_bRTSCTS);
DDX_Check(pDX, IDC_XON_XOFF, m_bXONXOFF);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCommSettingsDlg, CDialog)
//{{AFX_MSG_MAP(CCommSettingsDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCommSettingsDlg message handlers
void CCommSettingsDlg::OnOK()
{
// update various dialog data members
UpdateData(TRUE);
CString strCommSection;
strCommSection.LoadString(IDS_COMMSECTION);
CString strCommBaudRateItem;
strCommBaudRateItem.LoadString(IDS_COMMBAUDRATE);
::AfxGetApp()->WriteProfileInt(strCommSection, strCommBaudRateItem, GetBaudRate());
CString strCommDataBitsItem;
strCommDataBitsItem.LoadString(IDS_COMMDATABITS);
::AfxGetApp()->WriteProfileInt(strCommSection, strCommDataBitsItem, GetDataBits());
CString strCommStopBitsItem;
strCommStopBitsItem.LoadString(IDS_COMMSTOPBITS);
::AfxGetApp()->WriteProfileInt(strCommSection, strCommStopBitsItem, GetStopBits());
CString strCommParityItem;
strCommParityItem.LoadString(IDS_COMMPARITY);
::AfxGetApp()->WriteProfileInt(strCommSection, strCommParityItem, GetParity());
CString strCommPortItem;
strCommPortItem.LoadString(IDS_COMMPORT);
::AfxGetApp()->WriteProfileInt(strCommSection, strCommPortItem, GetCommPort());
CString strCommFlowCtrlItem;
strCommFlowCtrlItem.LoadString(IDS_COMMFLOWCTRL);
::AfxGetApp()->WriteProfileInt(strCommSection, strCommFlowCtrlItem, GetFlowCtrls());
EndDialog(IDOK);
}
DWORD CCommSettingsDlg::GetBaudRate(void)
{
switch (m_baud)
{
case 0:
return CBR_300;
break;
case 1:
return CBR_600;
break;
case 2:
return CBR_1200;
break;
case 3:
return CBR_2400;
break;
case 4:
return CBR_4800;
break;
case 5:
return CBR_9600;
default:
ASSERT(FALSE);
return DEFAULT_BUADRATE;
}
}
BYTE CCommSettingsDlg::GetDataBits(void)
{
switch (m_databits)
{
case 0:
return 7;
break;
case 1:
return 8;
break;
default:
ASSERT(FALSE);
return DEFAULT_DATABITS;
}
}
BYTE CCommSettingsDlg::GetStopBits(void)
{
switch (m_stopbits)
{
case 0:
return ONESTOPBIT;
break;
case 1:
return TWOSTOPBITS;
break;
default:
ASSERT(FALSE);
return ONESTOPBIT;
}
}
BYTE CCommSettingsDlg::GetParity(void)
{
switch (m_parity)
{
case 0:
return NOPARITY;
break;
case 1:
return ODDPARITY;
break;
case 2:
return EVENPARITY;
break;
default:
ASSERT(FALSE);
return NOPARITY;
}
}
BYTE CCommSettingsDlg::GetCommPort(void)
{
return m_comport + 1;
}
BYTE CCommSettingsDlg::GetFlowCtrls(void)
{
BYTE byteFlowCtrl = 0;
if (m_bDTRDSR)
byteFlowCtrl |= PCF_DTRDSR;
if (m_bRTSCTS)
byteFlowCtrl |= PCF_RTSCTS;
if (m_bXONXOFF)
byteFlowCtrl |= PCF_XONXOFF;
return byteFlowCtrl;
}
BOOL CCommSettingsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCommSettingsDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -