-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDlgIPSet.cpp
187 lines (160 loc) · 4.59 KB
/
DlgIPSet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// DlgIPSet.cpp : implementation file
//
#include "stdafx.h"
#include "SIPCall.h"
#include "DlgIPSet.h"
#include "afxdialogex.h"
#include "DecodeMsg.h"
#include "SIPCallDlg.h"
// CDlgIPSet dialog
IMPLEMENT_DYNAMIC(CDlgIPSet, CDialogEx)
CDlgIPSet::CDlgIPSet(CWnd* pParent /*=NULL*/)
: CDialogEx(CDlgIPSet::IDD, pParent)
{
}
CDlgIPSet::~CDlgIPSet()
{
}
void CDlgIPSet::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_IPADDRESS_MAIN, m_ctrlIPMain);
DDX_Control(pDX, IDC_IPADDRESS_SUB, m_ctrlIPSub);
DDX_Control(pDX, IDC_LIST1, m_ctrlListIP);
}
BEGIN_MESSAGE_MAP(CDlgIPSet, CDialogEx)
ON_BN_CLICKED(IDOK, &CDlgIPSet::OnBnClickedOk)
ON_BN_CLICKED(IDC_BTN_ADD_SUB, &CDlgIPSet::OnBnClickedBtnAddSub)
ON_BN_CLICKED(IDC_BTN_DEL_SUB, &CDlgIPSet::OnBnClickedBtnDelSub)
ON_BN_CLICKED(IDC_RADIO_MAIN, &CDlgIPSet::OnBnClickedRadioMain)
ON_BN_CLICKED(IDC_RADIO_SUB, &CDlgIPSet::OnBnClickedRadioSub)
END_MESSAGE_MAP()
// CDlgIPSet message handlers
void CDlgIPSet::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
int nNum = 0;
SIPData* pData = g_MSG.GetIPData(nNum);
int nMainSystem = ((CButton*)GetDlgItem(IDC_RADIO_MAIN))->GetCheck();
if(nNum > 0 ){
unsigned char *pIP;
DWORD dwIP;
m_ctrlIPMain.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
sprintf(pData[0].ip, ("%u.%u.%u.%u"),*(pIP+3), *(pIP+2), *(pIP+1), *pIP);
g_MSG.SaveIPData();
if (nMainSystem)
{
if (nNum == 1)
{
MessageBox(L"请把分控IP添加到List中!", L"提醒");
}
else{
g_Config.m_SystemConfig.nMainSystem = nMainSystem;
g_Config.m_ini.SetMainFlag(nMainSystem);
CDialogEx::OnOK();
}
}
else{
g_Config.m_SystemConfig.nMainSystem = nMainSystem;
g_Config.m_ini.SetMainFlag(nMainSystem);
CDialogEx::OnOK();
}
}
else{
MessageBox(L"请设置主分控IP", L"提醒");
}
}
void CDlgIPSet::OnBnClickedBtnAddSub()
{
// TODO: Add your control notification handler code here
unsigned char *pIP;
DWORD dwIP;
m_ctrlIPSub.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
SIPData data;
data.type = 2;
sprintf(data.ip, ("%u.%u.%u.%u"),*(pIP+3), *(pIP+2), *(pIP+1), *pIP);
g_MSG.AddIPData(data);
wchar_t wName[256] = {0};
MultiByteToWideChar(CP_ACP, 0, data.ip, -1, wName, 256);
m_ctrlListIP.AddString(wName);
}
void CDlgIPSet::OnBnClickedBtnDelSub()
{
// TODO: Add your control notification handler code here
int curSel = m_ctrlListIP.GetCurSel();
if (curSel != -1)
{
CString strName;
m_ctrlListIP.GetText(curSel, strName);
char IP[32] = {0};
WideCharToMultiByte(CP_ACP, 0, strName, -1, IP, 32, NULL, NULL);
g_MSG.DelIPData(IP);
m_ctrlListIP.DeleteString(curSel);
}
}
void CDlgIPSet::LoadIpData()
{
m_ctrlListIP.ResetContent();
int nNum = 0;
SIPData* pData = g_MSG.GetIPData(nNum);
if (nNum > 0)
{
DWORD dwIP = inet_addr(pData[0].ip);
unsigned char *pIP = (unsigned char*)&dwIP;
m_ctrlIPMain.SetAddress(*pIP, *(pIP+1), *(pIP+2), *(pIP+3));
for (int i = 1; i < nNum; i++)
{
wchar_t wName[256] = {0};
MultiByteToWideChar(CP_ACP, 0, pData[i].ip, -1, wName, 256);
m_ctrlListIP.AddString(wName);
}
}
}
BOOL CDlgIPSet::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
LoadIpData();
if (g_Config.m_SystemConfig.nMainSystem)
{
((CButton*)GetDlgItem(IDC_RADIO_MAIN))->SetCheck(1);
SetLayout(1);
}
else{
((CButton*)GetDlgItem(IDC_RADIO_SUB))->SetCheck(1);
SetLayout(0);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgIPSet::SetLayout(int bMain)
{
if (bMain)
{
GetDlgItem(IDC_IPADDRESS_SUB)->EnableWindow(TRUE);
GetDlgItem(IDC_BTN_ADD_SUB)->EnableWindow(TRUE);
GetDlgItem(IDC_BTN_DEL_SUB)->EnableWindow(TRUE);
GetDlgItem(IDC_LIST1)->EnableWindow(TRUE);
}
else{
GetDlgItem(IDC_IPADDRESS_SUB)->EnableWindow(FALSE);
GetDlgItem(IDC_BTN_ADD_SUB)->EnableWindow(FALSE);
GetDlgItem(IDC_BTN_DEL_SUB)->EnableWindow(FALSE);
GetDlgItem(IDC_LIST1)->EnableWindow(FALSE);
}
}
void CDlgIPSet::OnBnClickedRadioMain()
{
// TODO: Add your control notification handler code here
SetLayout(1);
DWORD dwIP = inet_addr(g_MSG.GetHostIP());
unsigned char *pIP = (unsigned char*)&dwIP;
m_ctrlIPMain.SetAddress(*pIP, *(pIP+1), *(pIP+2), *(pIP+3));
}
void CDlgIPSet::OnBnClickedRadioSub()
{
// TODO: Add your control notification handler code here
SetLayout(0);
}