代码拉取完成,页面将自动刷新
#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);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。