📄 addcom.cpp
字号:
// AddCom.cpp : implementation file
//
#include "stdafx.h"
#include "RegionComm.h"
#include "AddCom.h"
#include "RegionCommDoc.h"
#include "Communication.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddCom dialog
CAddCom::CAddCom(CWnd* pParent /*=NULL*/)
: CDialog(CAddCom::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddCom)
m_sComPort = _T("");
m_sBaud = _T("");
m_Depict = _T("");
m_sDeviceNo = -1;
m_sDeviceType = -1;
//}}AFX_DATA_INIT
}
void CAddCom::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddCom)
DDX_Control(pDX, IDC_COMBO_DTYPE, m_DeviceType);
DDX_Control(pDX, IDC_COMBO_DNO, m_DeviceNo);
DDX_Control(pDX, IDOK, m_Ok_C);
DDX_Control(pDX, IDC_COMBO_COMPORT, m_ComPort_C);
DDX_Control(pDX, IDC_COMBO_BAUD, m_Baud_C);
DDX_CBString(pDX, IDC_COMBO_COMPORT, m_sComPort);
DDX_CBString(pDX, IDC_COMBO_BAUD, m_sBaud);
DDX_Text(pDX, IDC_EDIT_DEPICT, m_Depict);
DDV_MaxChars(pDX, m_Depict, 60);
DDX_CBString(pDX, IDC_COMBO_DNO, m_sDeviceNo);
DDX_CBString(pDX, IDC_COMBO_DTYPE, m_sDeviceType);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddCom, CDialog)
//{{AFX_MSG_MAP(CAddCom)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddCom message handlers
void CAddCom::OnOK()
{
CRegionCommDoc * pDoc;
int nPort;
DWORD dwBauRate;
BYTE nDeviceType;
BYTE nDeviceNo;
CString sDepict;
UpdateData();
pDoc = (CRegionCommDoc *)((CFrameWnd *)AfxGetMainWnd())->GetActiveDocument();
m_sComPort.TrimLeft();
m_sComPort.TrimRight();
m_sComPort=m_sComPort.Mid(3);
m_sComPort.TrimLeft();
m_sComPort.TrimRight();
if(m_sComPort=="")
return;
nPort = atoi(m_sComPort);
dwBauRate = (DWORD)atol(LPCTSTR(m_sBaud));
m_sDeviceType.TrimLeft();
m_sDeviceType.TrimRight();
nDeviceType=atoi(m_sDeviceType);
m_sDeviceNo.TrimLeft();
m_sDeviceNo.TrimRight();
nDeviceNo=atoi(m_sDeviceNo);
m_Depict.TrimLeft();
m_Depict.TrimRight();
sDepict=m_Depict;
CCommunication * pCommunication;
pCommunication = pDoc->m_pCommunication;
int j;
for (j = 0; j < pCommunication->m_aCom.GetSize(); j++)
if (pCommunication->m_aCom[j]->m_DeviceType == nDeviceType && pCommunication->m_aCom[j]->m_DeviceNo == nDeviceNo )
{
MessageBox(_T("当前设备类型、设备号已经使用!"), _T("错误"), MB_OK | MB_ICONSTOP);
return;
}
if (!pDoc->m_pCommunication->AddTscCom((BYTE)nPort, dwBauRate,nDeviceType,nDeviceNo,sDepict))
{
MessageBox(_T("无法打开指定的通讯口!"), _T("错误"), MB_OK | MB_ICONSTOP);
return;
}
m_PortNo = (BYTE)nPort;
CDialog::OnOK();
}
BOOL CAddCom::OnInitDialog()
{
CDialog::OnInitDialog();
CRegionCommDoc * pDoc;
pDoc = (CRegionCommDoc *)((CFrameWnd *)AfxGetMainWnd())->GetActiveDocument();
BYTE PortNo;
int i,j;
CString str;
CCommunication * pCommunication;
pCommunication = pDoc->m_pCommunication;
BOOL HasBeenIndex=FALSE;
int index;
for (i = 1; i < 255; i++)
{
PortNo = (BYTE)i;
BOOL HasBeenOpend=FALSE;
for (j = 0; j < pCommunication->m_aCom.GetSize(); j++)
if (pCommunication->m_aCom[j]->m_ComPort == (BYTE)PortNo)
{
HasBeenOpend=TRUE;
break;
}
if (!HasBeenOpend)
{
str.Format("COM%d", i);
m_ComPort_C.AddString((LPCTSTR)str);
if(!HasBeenIndex)
{
HasBeenIndex=TRUE;
index=i;
}
}
str.Format("%d", i);
m_DeviceNo.AddString((LPCTSTR)str);
}
m_DeviceType.AddString("信号机");
m_DeviceType.AddString("情报板");
if (m_ComPort_C.GetCount() == 0)
m_Ok_C.EnableWindow(FALSE);
else
{
m_ComPort_C.SetCurSel(0);
m_DeviceType.SetCurSel(0);
m_DeviceNo.SetCurSel(index-1);
}
m_Baud_C.AddString("1200");
m_Baud_C.AddString("2400");
m_Baud_C.AddString("4800");
m_Baud_C.AddString("9600");
m_Baud_C.AddString("19200");
m_Baud_C.AddString("28800");
m_Baud_C.AddString("28400");
m_Baud_C.AddString("57600");
m_Baud_C.AddString("115200");
m_Baud_C.SetCurSel(3);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -