// CDialogCommSet1.cpp: 实现文件
|
//
|
|
#include "pch.h"
|
#include "MultiTerminal1.h"
|
#include "CDialogCommSet1.h"
|
#include "afxdialogex.h"
|
#include <devguid.h>
|
#include <SetupAPI.h>
|
#include <Dbt.h>
|
|
// CDialogCommSet1 对话框
|
|
IMPLEMENT_DYNAMIC(CDialogCommSet1, CDialogEx)
|
|
CDialogCommSet1::CDialogCommSet1(CWnd* pParent /*=nullptr*/)
|
: CDialogEx(IDD_DIALOG_COMMSET1, pParent)
|
{
|
|
}
|
|
CDialogCommSet1::~CDialogCommSet1()
|
{
|
}
|
|
void CDialogCommSet1::DoDataExchange(CDataExchange* pDX)
|
{
|
CDialogEx::DoDataExchange(pDX);
|
DDX_Control(pDX, IDC_COMBO_PORT, m_combo_comport);
|
}
|
|
|
BEGIN_MESSAGE_MAP(CDialogCommSet1, CDialogEx)
|
|
ON_WM_DEVICECHANGE()
|
|
ON_BN_CLICKED(IDOK, &CDialogCommSet1::OnBnClickedOk)
|
ON_BN_CLICKED(IDC_BUTTON1, &CDialogCommSet1::OnBnClickedButton1)
|
END_MESSAGE_MAP()
|
|
|
// CDialogCommSet1 消息处理程序
|
|
BOOL CDialogCommSet1::OnInitDialog()
|
{
|
CDialogEx::OnInitDialog();
|
|
// TODO: 在此添加额外的初始化
|
ShowParams();
|
return TRUE; // return TRUE unless you set the focus to a control
|
// 异常: OCX 属性页应返回 FALSE
|
}
|
|
int CDialogCommSet1::UpdateComPortList()
|
{
|
// TODO: 在此处添加实现代码.
|
CString s1, s2;
|
|
m_combo_comport.ResetContent();
|
for (int i = 1; i <= 16; i++)
|
{
|
s1.Format(_T("COM%d"), i);
|
if (get_com_name(s1, s2)) s1 = s2;
|
m_combo_comport.AddString(s1);
|
}
|
sComSelStr = _T("COM3");
|
m_combo_comport.SelectString(0, sComSelStr);
|
m_combo_comport.SetCurSel(2);
|
return 0;
|
HKEY hKey;
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Hardware\\DeviceMap\\SerialComm"), NULL, KEY_READ, &hKey) == ERROR_SUCCESS)
|
{
|
TCHAR szPortName[256], szComName[256];
|
DWORD dwLong, dwSize;
|
int nCount = 0;
|
|
m_combo_comport.ResetContent();
|
while (true)
|
{
|
dwLong = dwSize = 256;
|
if (RegEnumValue(hKey, nCount, szPortName, &dwLong, NULL, NULL, (PUCHAR)szComName, &dwSize) == ERROR_NO_MORE_ITEMS)
|
break;
|
|
m_combo_comport.InsertString(nCount, szComName);
|
nCount++;
|
}
|
RegCloseKey(hKey);
|
m_combo_comport.SetCurSel(0);
|
}
|
|
return 0;
|
}
|
|
BOOL CDialogCommSet1::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
|
{
|
if (nEventType == DBT_DEVNODES_CHANGED)
|
UpdateComPortList();
|
|
return TRUE;
|
}
|
|
int CDialogCommSet1::DisplayParams()
|
{
|
// TODO: 在此处添加实现代码.
|
return 0;
|
}
|
|
int CDialogCommSet1::ShowParams()
|
{
|
// TODO: 在此处添加实现代码.
|
((CComboBox *)GetDlgItem(IDC_COMBO_NETWORK_TYPE))->SetCurSel(0);
|
((CComboBox *)GetDlgItem(IDC_COMBO_PORT))->SetCurSel(0);
|
((CComboBox *)GetDlgItem(IDC_COMBO_BAUD))->SetCurSel(8);
|
|
((CButton *)GetDlgItem(IDC_RADIO_DATA_LENGTH_8B))->SetCheck(1);
|
|
((CButton *)GetDlgItem(IDC_RADIO_STOP_1B))->SetCheck(1);
|
|
((CButton *)GetDlgItem(IDC_RADIO_PARITY_NONE))->SetCheck(1);
|
|
((CComboBox *)GetDlgItem(IDC_COMBO_COMM_TIMEOUT))->SetCurSel(5);
|
((CButton *)GetDlgItem(IDC_CHECK_AUTO_BAUD))->SetCheck(1);
|
((CButton *)GetDlgItem(IDC_CHECK_AUTO_DATA_LENGTH))->SetCheck(1);
|
((CButton *)GetDlgItem(IDC_CHECK_AUTO_PARITY))->SetCheck(1);
|
|
UpdateComPortList();
|
return 0;
|
}
|
|
int CDialogCommSet1::GetParams()
|
{
|
// TODO: 在此处添加实现代码.
|
return 0;
|
}
|
|
void CDialogCommSet1::OnOK()
|
{
|
// TODO: 在此添加专用代码和/或调用基类
|
GetParams();
|
CDialogEx::OnOK();
|
}
|
|
|
|
void CDialogCommSet1::OnBnClickedOk()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
CDialogEx::OnOK();
|
}
|
|
|
void CDialogCommSet1::OnBnClickedButton1()
|
{
|
// TODO: 在此添加控件通知处理程序代码
|
}
|