提交 | 用户 | age
|
0ed438
|
1 |
// CDialogCommSet1.cpp: 实现文件
|
Q |
2 |
//
|
|
3 |
|
|
4 |
#include "pch.h"
|
|
5 |
#include "MTerm2.h"
|
65f713
|
6 |
#include "DialogCommSet1.h"
|
0ed438
|
7 |
#include "afxdialogex.h"
|
Q |
8 |
#include <devguid.h>
|
|
9 |
#include <SetupAPI.h>
|
|
10 |
#include <Dbt.h>
|
|
11 |
|
|
12 |
// CDialogCommSet1 对话框
|
|
13 |
|
|
14 |
IMPLEMENT_DYNAMIC(CDialogCommSet1, CDialogEx)
|
|
15 |
|
|
16 |
CDialogCommSet1::CDialogCommSet1(CWnd* pParent /*=nullptr*/)
|
|
17 |
: CDialogEx(IDD_DIALOG_COMMSET1, pParent)
|
|
18 |
{
|
|
19 |
|
|
20 |
}
|
|
21 |
|
|
22 |
CDialogCommSet1::~CDialogCommSet1()
|
|
23 |
{
|
|
24 |
}
|
|
25 |
|
|
26 |
void CDialogCommSet1::DoDataExchange(CDataExchange* pDX)
|
|
27 |
{
|
|
28 |
CDialogEx::DoDataExchange(pDX);
|
|
29 |
DDX_Control(pDX, IDC_COMBO_PORT, m_combo_comport);
|
|
30 |
}
|
|
31 |
|
|
32 |
|
|
33 |
BEGIN_MESSAGE_MAP(CDialogCommSet1, CDialogEx)
|
|
34 |
|
|
35 |
ON_WM_DEVICECHANGE()
|
|
36 |
|
|
37 |
ON_BN_CLICKED(IDOK, &CDialogCommSet1::OnBnClickedOk)
|
|
38 |
ON_BN_CLICKED(IDC_BUTTON1, &CDialogCommSet1::OnBnClickedButton1)
|
|
39 |
END_MESSAGE_MAP()
|
|
40 |
|
|
41 |
|
|
42 |
// CDialogCommSet1 消息处理程序
|
|
43 |
|
|
44 |
BOOL CDialogCommSet1::OnInitDialog()
|
|
45 |
{
|
|
46 |
CDialogEx::OnInitDialog();
|
|
47 |
|
|
48 |
// TODO: 在此添加额外的初始化
|
|
49 |
ShowParams();
|
|
50 |
return TRUE; // return TRUE unless you set the focus to a control
|
|
51 |
// 异常: OCX 属性页应返回 FALSE
|
|
52 |
}
|
|
53 |
|
|
54 |
int CDialogCommSet1::UpdateComPortList()
|
|
55 |
{
|
|
56 |
// TODO: 在此处添加实现代码.
|
|
57 |
CString s1, s2;
|
|
58 |
|
|
59 |
m_combo_comport.ResetContent();
|
|
60 |
for (int i = 1; i <= 16; i++)
|
|
61 |
{
|
|
62 |
s1.Format(_T("COM%d"), i);
|
|
63 |
if (get_com_name(s1, s2)) s1 = s2;
|
|
64 |
m_combo_comport.AddString(s1);
|
|
65 |
}
|
|
66 |
sComSelStr = _T("COM3");
|
|
67 |
m_combo_comport.SelectString(0, sComSelStr);
|
|
68 |
m_combo_comport.SetCurSel(2);
|
|
69 |
return 0;
|
|
70 |
HKEY hKey;
|
|
71 |
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Hardware\\DeviceMap\\SerialComm"), NULL, KEY_READ, &hKey) == ERROR_SUCCESS)
|
|
72 |
{
|
|
73 |
TCHAR szPortName[256], szComName[256];
|
|
74 |
DWORD dwLong, dwSize;
|
|
75 |
int nCount = 0;
|
|
76 |
|
|
77 |
m_combo_comport.ResetContent();
|
|
78 |
while (true)
|
|
79 |
{
|
|
80 |
dwLong = dwSize = 256;
|
|
81 |
if (RegEnumValue(hKey, nCount, szPortName, &dwLong, NULL, NULL, (PUCHAR)szComName, &dwSize) == ERROR_NO_MORE_ITEMS)
|
|
82 |
break;
|
|
83 |
|
|
84 |
m_combo_comport.InsertString(nCount, szComName);
|
|
85 |
nCount++;
|
|
86 |
}
|
|
87 |
RegCloseKey(hKey);
|
|
88 |
m_combo_comport.SetCurSel(0);
|
|
89 |
}
|
|
90 |
|
|
91 |
return 0;
|
|
92 |
}
|
|
93 |
|
|
94 |
BOOL CDialogCommSet1::OnDeviceChange(UINT nEventType, DWORD_PTR dwData)
|
|
95 |
{
|
|
96 |
if (nEventType == DBT_DEVNODES_CHANGED)
|
|
97 |
UpdateComPortList();
|
|
98 |
|
|
99 |
return TRUE;
|
|
100 |
}
|
|
101 |
|
|
102 |
int CDialogCommSet1::DisplayParams()
|
|
103 |
{
|
|
104 |
// TODO: 在此处添加实现代码.
|
|
105 |
return 0;
|
|
106 |
}
|
|
107 |
|
|
108 |
int CDialogCommSet1::ShowParams()
|
|
109 |
{
|
|
110 |
// TODO: 在此处添加实现代码.
|
|
111 |
((CComboBox *)GetDlgItem(IDC_COMBO_NETWORK_TYPE))->SetCurSel(0);
|
|
112 |
((CComboBox *)GetDlgItem(IDC_COMBO_PORT))->SetCurSel(0);
|
|
113 |
((CComboBox *)GetDlgItem(IDC_COMBO_BAUD))->SetCurSel(8);
|
|
114 |
|
|
115 |
((CButton *)GetDlgItem(IDC_RADIO_DATA_LENGTH_8B))->SetCheck(1);
|
|
116 |
|
|
117 |
((CButton *)GetDlgItem(IDC_RADIO_STOP_1B))->SetCheck(1);
|
|
118 |
|
|
119 |
((CButton *)GetDlgItem(IDC_RADIO_PARITY_NONE))->SetCheck(1);
|
|
120 |
|
|
121 |
((CComboBox *)GetDlgItem(IDC_COMBO_COMM_TIMEOUT))->SetCurSel(5);
|
|
122 |
((CButton *)GetDlgItem(IDC_CHECK_AUTO_BAUD))->SetCheck(1);
|
|
123 |
((CButton *)GetDlgItem(IDC_CHECK_AUTO_DATA_LENGTH))->SetCheck(1);
|
|
124 |
((CButton *)GetDlgItem(IDC_CHECK_AUTO_PARITY))->SetCheck(1);
|
|
125 |
|
|
126 |
UpdateComPortList();
|
|
127 |
return 0;
|
|
128 |
}
|
|
129 |
|
|
130 |
int CDialogCommSet1::GetParams()
|
|
131 |
{
|
|
132 |
// TODO: 在此处添加实现代码.
|
|
133 |
((CComboBox *)GetDlgItem(IDC_COMBO_NETWORK_TYPE))->GetCurSel();
|
|
134 |
m_nComNum = ((CComboBox *)GetDlgItem(IDC_COMBO_PORT))->GetCurSel() + 1;
|
|
135 |
//((CComboBox *)GetDlgItem(IDC_COMBO_BAUD))->GetCurSel();
|
|
136 |
CString baudstr;
|
|
137 |
GetDlgItemText(IDC_COMBO_BAUD, baudstr);
|
|
138 |
m_nBaudRate = _tstoi(baudstr);
|
|
139 |
m_Settings = "8,N,1";
|
|
140 |
|
|
141 |
((CButton *)GetDlgItem(IDC_RADIO_DATA_LENGTH_8B))->GetCheck();
|
|
142 |
|
|
143 |
((CButton *)GetDlgItem(IDC_RADIO_STOP_1B))->GetCheck();
|
|
144 |
|
|
145 |
((CButton *)GetDlgItem(IDC_RADIO_PARITY_NONE))->GetCheck();
|
|
146 |
|
|
147 |
((CComboBox *)GetDlgItem(IDC_COMBO_COMM_TIMEOUT))->GetCurSel();
|
|
148 |
((CButton *)GetDlgItem(IDC_CHECK_AUTO_BAUD))->GetCheck();
|
|
149 |
((CButton *)GetDlgItem(IDC_CHECK_AUTO_DATA_LENGTH))->GetCheck();
|
|
150 |
((CButton *)GetDlgItem(IDC_CHECK_AUTO_PARITY))->GetCheck();
|
|
151 |
|
|
152 |
return 0;
|
|
153 |
}
|
|
154 |
|
|
155 |
void CDialogCommSet1::OnOK()
|
|
156 |
{
|
|
157 |
// TODO: 在此添加专用代码和/或调用基类
|
|
158 |
GetParams();
|
|
159 |
CDialogEx::OnOK();
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
void CDialogCommSet1::OnBnClickedOk()
|
|
165 |
{
|
|
166 |
// TODO: 在此添加控件通知处理程序代码
|
|
167 |
GetParams();
|
|
168 |
CDialogEx::OnOK();
|
|
169 |
}
|
|
170 |
|
|
171 |
|
|
172 |
void CDialogCommSet1::OnBnClickedButton1()
|
|
173 |
{
|
|
174 |
// TODO: 在此添加控件通知处理程序代码
|
|
175 |
}
|