1 Star 0 Fork 0

yyj8209/HikVisionStation

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
CDlgComm.cpp 2.47 KB
一键复制 编辑 原始数据 按行查看 历史
#include "stdafx.h"
#include "CDlgComm.h"
#include "afxdialogex.h"
#include <resource.h>
// CDlgCommSettings 对话框
IMPLEMENT_DYNAMIC(CDlgComm, CDialog)
CDlgComm::CDlgComm(CWnd* pParent /*=nullptr*/)
: CDialog(IDD_DLG_COMM, pParent)
{
}
CDlgComm::~CDlgComm()
{
}
void CDlgComm::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO_COMM_ID, m_cmboxCommID);
DDX_Control(pDX, IDC_COMBO_BAUD, m_cmboxBaud);
DDX_Control(pDX, IDC_COMBO_DATA, m_cmboxData);
DDX_Control(pDX, IDC_COMBO_STOP, m_cmboxStop);
DDX_Control(pDX, IDC_COMBO_CHECK, m_cmboxCheck);
}
BEGIN_MESSAGE_MAP(CDlgComm, CDialog)
ON_CBN_SELCHANGE(IDC_COMBO_COMM_ID, &CDlgComm::OnCbnSelchangeComboCommId)
ON_CBN_SELCHANGE(IDC_COMBO_BAUD, &CDlgComm::OnCbnSelchangeComboBaud)
END_MESSAGE_MAP()
BOOL CDlgComm::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
InitUI();
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
// CDlgComm消息处理程序
void CDlgComm::InitUI() {
m_cmboxData.SetCurSel(0);
m_cmboxStop.SetCurSel(0);
m_cmboxCheck.SetCurSel(0);
GetComList_256();
int iBaud[5] = {9600,19200,38400,57600,115200};
CString tmp;
for (int i = 0; i < 5; i++) {
tmp.Format("%d", iBaud[i]);
m_cmboxBaud.AddString(tmp);
}
m_cmboxBaud.SetCurSel(0);
n_iBaud = 9600;
}
void CDlgComm::GetComList_256()//获取可用com口支持到256个
{
CString strCom, strComOpen;
int nCom = 0;
int count = 0;
HANDLE hCom;
m_cmboxCommID.ResetContent();
do
{
nCom++;
strCom.Format("COM%d", nCom);
strComOpen.Format("\\\\.\\COM%d", nCom);
hCom = CreateFile(strComOpen, GENERIC_READ | GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (INVALID_HANDLE_VALUE == hCom)
{
DWORD error = ::GetLastError();//取得错误信息
}
else
{
m_cmboxCommID.AddString(strCom);
count++;
}
CloseHandle(hCom);
} while (nCom < 256);
m_cmboxCommID.SetCurSel(0);
m_cmboxCommID.GetWindowTextA(n_strComm);
}
void CDlgComm::OnCbnSelchangeComboCommId()
{
// TODO: 在此添加控件通知处理程序代码
int iPos = m_cmboxCommID.GetCurSel();//当 前选中的行。
m_cmboxCommID.GetLBText(iPos, n_strComm);
}
void CDlgComm::OnCbnSelchangeComboBaud()
{
// TODO: 在此添加控件通知处理程序代码
int iPos = m_cmboxBaud.GetCurSel();//当 前选中的行。
CString strBaud;
m_cmboxBaud.GetLBText(iPos, strBaud);
n_iBaud = atoi(strBaud);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/yyj8209/hik-vision-station.git
git@gitee.com:yyj8209/hik-vision-station.git
yyj8209
hik-vision-station
HikVisionStation
master

搜索帮助