-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVpnDialup2Dlg.cpp
393 lines (325 loc) · 9.79 KB
/
VpnDialup2Dlg.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// VpnDialup2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "VpnDialup2.h"
#include "VpnDialup2Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////////
#include <strsafe.h>
#pragma comment(lib,"strsafe.lib")
NOTIFYICONDATAW g_notify = {0};
static const UINT uId = 0x4444;
static const UINT WMU_DIALUPTRAY =
::RegisterWindowMessageW(L"Netspeed_runsisi@HUST");
static const wchar_t* wszTip = L"ÍøÂç¼ÓËÙÆ÷ by runsisi@HUST\n"
L"http://www.pathtome.com/";
static const wchar_t* wszInfoTitle = L"runsisi@163.com";
static const wchar_t* wszInfo = L"ÍøÂç¼ÓËÙÆ÷ by runsisi@HUST\n"
L"http://www.pathtome.com/";
extern UINT WMU_VPNCONNECTED;
//////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
private:
RUNSISI_HUST::CHyperLinkCtrl m_vendor;
public:
virtual BOOL OnInitDialog();
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_VENDOR, m_vendor);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CVpnDialup2Dlg dialog
CVpnDialup2Dlg::CVpnDialup2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CVpnDialup2Dlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CVpnDialup2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CHECK1, m_quietModeCheckBox);
DDX_Control(pDX, IDC_BLOG, m_blog);
}
BEGIN_MESSAGE_MAP(CVpnDialup2Dlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CVpnDialup2Dlg::OnBnClickedButton1)
// ON_BN_CLICKED(IDC_CHECK1, &CVpnDialup2Dlg::OnBnClickedCheck1)
ON_WM_CLOSE()
ON_REGISTERED_MESSAGE(WMU_DIALUPTRAY, &CVpnDialup2Dlg::OnDialupTray)
ON_BN_CLICKED(IDOK, &CVpnDialup2Dlg::OnBnClickedOk)
ON_WM_SIZE()
ON_REGISTERED_MESSAGE(WMU_VPNCONNECTED, &CVpnDialup2Dlg::OnVpnConnected)
ON_COMMAND(ID_POPUPMENU_EXIT, &CVpnDialup2Dlg::OnPopupmenuExit)
ON_COMMAND(ID_POPUPMENU_MAINWINDOW, &CVpnDialup2Dlg::OnPopupmenuMainwindow)
ON_COMMAND(ID_POPUPMENU_ABOUT, &CVpnDialup2Dlg::OnPopupmenuAbout)
ON_WM_DRAWITEM()
ON_WM_MEASUREITEM()
END_MESSAGE_MAP()
// CVpnDialup2Dlg message handlers
BOOL CVpnDialup2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_quietModeCheckBox.SetCheck(BST_CHECKED);
g_notify.cbSize = sizeof(g_notify);
g_notify.hWnd = this->m_hWnd;
g_notify.uID = uId;
g_notify.uFlags = NIF_ICON | NIF_MESSAGE | NIF_INFO | NIF_TIP;
g_notify.uCallbackMessage = WMU_DIALUPTRAY;
g_notify.hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
StringCchCopyW(g_notify.szTip, 63, wszTip);
StringCchCopyW(g_notify.szInfo, 255, wszInfo);
g_notify.uTimeout = 20;
StringCchCopyW(g_notify.szInfoTitle, 63, wszInfoTitle);
g_notify.dwInfoFlags = NIIF_INFO;
m_blog.SetURL(TEXT("http://www.cppblog.com/runsisi"));
m_blog.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_CURSOR));
m_blog.CorrectLinkWidth();
m_imageList.Create(24, 24, ILC_COLOR8 | ILC_MASK, 0, 0);
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ABOUT));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_SHOWMAINWINDOW));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_EXIT));
m_imageList.Add(AfxGetApp()->LoadIcon(IDI_ABOUT));
m_popupMenu.LoadMenu(IDR_POPUPMENU);
m_popupMenu.ChangeMenuItem(&m_popupMenu, TRUE);
m_popupMenu.SetMenuImageList(&m_imageList);
return TRUE; // return TRUE unless you set the focus to a control
}
void CVpnDialup2Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CVpnDialup2Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CVpnDialup2Dlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
//////////////////////////////////////////////////////////////////////////
#include <process.h>
struct param_t
{
bool bQuiet;
HWND hMainWindow;
bool bFirstConnect;
};
param_t g_params = {false, 0, true};
extern unsigned __stdcall VpnThreadProc(void* p); //Parameter determine if we use
//quiet dial mode.
void CVpnDialup2Dlg::OnBnClickedButton1()
{
// TODO: Add your control notification handler code here
//Get quiet mode check box state.
bool bQuiet = true;
(m_quietModeCheckBox.GetCheck() == BST_CHECKED) ?
0 : bQuiet = false;
g_params.bQuiet = bQuiet;
g_params.hMainWindow = m_hWnd;
HANDLE hThread = (HANDLE)_beginthreadex(0, 0, VpnThreadProc,
0, 0, 0);
if (hThread)
{
CWnd* hConnect = GetDlgItem(IDC_BUTTON1);
hConnect->EnableWindow(FALSE);
CloseHandle(hThread);
GetDlgItem(IDC_STATUS)->SetWindowText(L"Connecting...Pls wait:)");
}
else
{
::MessageBoxW(0, L"BUG? Pls contact me!", L"BUG?",
MB_OK | MB_ICONINFORMATION);
}
}
//void CVpnDialup2Dlg::OnBnClickedCheck1()
//{
// // TODO: Add your control notification handler code here
//}
void CVpnDialup2Dlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
::Shell_NotifyIconW(NIM_ADD, &g_notify);
ShowWindow(SW_HIDE);
//CDialog::OnClose();
}
LRESULT CVpnDialup2Dlg::OnDialupTray(WPARAM wParam, LPARAM lParam)
{
if (lParam == WM_LBUTTONDOWN)
{
::Shell_NotifyIconW(NIM_DELETE, &g_notify);
ShowWindow(SW_SHOWNORMAL);
::SetWindowPos(this->m_hWnd, HWND_TOPMOST,
0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}
else if (lParam == WM_RBUTTONUP)
{
SetForegroundWindow();
POINT pt = {0};
::GetCursorPos(&pt);
// CMenu popupMenu;
// popupMenu.LoadMenu(IDR_POPUPMENU);
// popupMenu.GetSubMenu(0)->TrackPopupMenu(
// TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN,
// pt.x, pt.y, this);
//m_popupMenu.LoadMenu(IDR_POPUPMENU);
m_popupMenu.GetSubMenu(0)->TrackPopupMenu(
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN,
pt.x, pt.y, this);
// popupMenu.GetSubMenu(0)->TrackPopupMenu(
// TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN,
// GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), this);
}
return 0;
}
void CVpnDialup2Dlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
::Shell_NotifyIconW(NIM_DELETE, &g_notify);
OnOK();
}
void CVpnDialup2Dlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if (nType == SIZE_MINIMIZED)
{
::Shell_NotifyIconW(NIM_ADD, &g_notify);
ShowWindow(SW_HIDE);
OnClose();
}
}
LRESULT CVpnDialup2Dlg::OnVpnConnected(
WPARAM wParam, LPARAM lParam)
{
if (wParam == 0) //Failed.
{
if (lParam == 1460)
{
GetDlgItem(IDC_STATUS)->SetWindowText(L"U canceled:)");
GetDlgItem(IDC_BUTTON1)->EnableWindow(TRUE);
}
else
{
GetDlgItem(IDC_STATUS)->SetWindowText(L"Restart to try again.");
}
}
else if (wParam == 1)
{
GetDlgItem(IDC_STATUS)->SetWindowText(L"Enjoy:)");
}
return 0;
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_vendor.SetURL(TEXT("http://www.pathtome.com"));
m_vendor.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_CURSOR));
m_vendor.CorrectLinkWidth();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CVpnDialup2Dlg::OnPopupmenuExit()
{
// TODO: Add your command handler code here
::Shell_NotifyIconW(NIM_DELETE, &g_notify);
OnOK();
}
void CVpnDialup2Dlg::OnPopupmenuMainwindow()
{
// TODO: Add your command handler code here
::Shell_NotifyIconW(NIM_DELETE, &g_notify);
ShowWindow(SW_SHOWNORMAL);
::SetWindowPos(this->m_hWnd, HWND_TOPMOST,
0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
}
void CVpnDialup2Dlg::OnPopupmenuAbout()
{
// TODO: Add your command handler code here
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CVpnDialup2Dlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
m_popupMenu.DrawItem(lpDrawItemStruct);
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
void CVpnDialup2Dlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
// TODO: Add your message handler code here and/or call default
m_popupMenu.MeasureItem(lpMeasureItemStruct);
CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}