forked from phuslu/taskbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
taskbar.cpp
executable file
·588 lines (535 loc) · 16.2 KB
/
taskbar.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
#define _WIN32_IE 0x0500
#include <windows.h>
#include <wininet.h>
#include <shellapi.h>
#include <stdio.h>
#include <wininet.h>
#include <io.h>
#include "ras.h"
#include "raserror.h"
#include "psapi.h"
#include "resource.h"
#pragma comment(lib, "rasapi32.lib")
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "psapi.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "wininet.lib")
#ifndef INTERNET_OPTION_PER_CONNECTION_OPTION
#define INTERNET_OPTION_PER_CONNECTION_OPTION 75
// Options used in INTERNET_PER_CONN_OPTON struct
#define INTERNET_PER_CONN_FLAGS 1
#define INTERNET_PER_CONN_PROXY_SERVER 2
#define INTERNET_PER_CONN_PROXY_BYPASS 3
#define INTERNET_PER_CONN_AUTOCONFIG_URL 4
#define INTERNET_PER_CONN_AUTODISCOVERY_FLAGS 5
// PER_CONN_FLAGS
#define PROXY_TYPE_DIRECT 0x00000001
#define PROXY_TYPE_PROXY 0x00000002
#define PROXY_TYPE_AUTO_PROXY_URL 0x00000004
#define PROXY_TYPE_AUTO_DETECT 0x00000008
typedef struct {
DWORD dwOption;
union {
DWORD dwValue;
LPTSTR pszValue;
FILETIME ftValue;
} Value;
} INTERNET_PER_CONN_OPTION, *LPINTERNET_PER_CONN_OPTION;
typedef struct {
DWORD dwSize;
LPTSTR pszConnection;
DWORD dwOptionCount;
DWORD dwOptionError;
LPINTERNET_PER_CONN_OPTION pOptions;
} INTERNET_PER_CONN_OPTION_LIST, *LPINTERNET_PER_CONN_OPTION_LIST;
#endif
extern "C" WINBASEAPI HWND WINAPI GetConsoleWindow();
#define NID_UID 123
#define WM_TASKBARNOTIFY WM_USER+20
#define WM_TASKBARNOTIFY_MENUITEM_SHOW (WM_USER + 21)
#define WM_TASKBARNOTIFY_MENUITEM_HIDE (WM_USER + 22)
#define WM_TASKBARNOTIFY_MENUITEM_RELOAD (WM_USER + 23)
#define WM_TASKBARNOTIFY_MENUITEM_ABOUT (WM_USER + 24)
#define WM_TASKBARNOTIFY_MENUITEM_EXIT (WM_USER + 25)
#define WM_TASKBARNOTIFY_MENUITEM_PROXYLIST_BASE (WM_USER + 26)
HINSTANCE hInst;
HWND hWnd;
HWND hConsole;
WCHAR szTitle[64] = L"";
WCHAR szWindowClass[16] = L"taskbar";
WCHAR szCommandLine[1024] = L"";
WCHAR szTooltip[512] = L"";
WCHAR szBalloon[512] = L"";
WCHAR szEnvironment[1024] = L"";
WCHAR szProxyString[2048] = L"";
CHAR szRasPbk[4096] = "";
WCHAR *lpProxyList[8] = {0};
volatile DWORD dwChildrenPid;
static DWORD MyGetProcessId(HANDLE hProcess)
{
// https://gist.github.com/kusma/268888
typedef DWORD (WINAPI *pfnGPI)(HANDLE);
typedef ULONG (WINAPI *pfnNTQIP)(HANDLE, ULONG, PVOID, ULONG, PULONG);
static int first = 1;
static pfnGPI pfnGetProcessId;
static pfnNTQIP ZwQueryInformationProcess;
if (first)
{
first = 0;
pfnGetProcessId = (pfnGPI)GetProcAddress(
GetModuleHandleW(L"KERNEL32.DLL"), "GetProcessId");
if (!pfnGetProcessId)
ZwQueryInformationProcess = (pfnNTQIP)GetProcAddress(
GetModuleHandleW(L"NTDLL.DLL"),
"ZwQueryInformationProcess");
}
if (pfnGetProcessId)
return pfnGetProcessId(hProcess);
if (ZwQueryInformationProcess)
{
struct
{
PVOID Reserved1;
PVOID PebBaseAddress;
PVOID Reserved2[2];
ULONG UniqueProcessId;
PVOID Reserved3;
} pbi;
ZwQueryInformationProcess(hProcess, 0, &pbi, sizeof(pbi), 0);
return pbi.UniqueProcessId;
}
return 0;
}
BOOL ShowTrayIcon(LPCTSTR lpszProxy, DWORD dwMessage=NIM_ADD)
{
NOTIFYICONDATA nid;
ZeroMemory(&nid, sizeof(NOTIFYICONDATA));
nid.cbSize = (DWORD)sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = NID_UID;
nid.uFlags = NIF_ICON|NIF_MESSAGE;
nid.dwInfoFlags=NIIF_INFO;
nid.uCallbackMessage = WM_TASKBARNOTIFY;
nid.hIcon = LoadIcon(hInst, (LPCTSTR)IDI_SMALL);
nid.uTimeoutAndVersion = 3 * 1000 | NOTIFYICON_VERSION;
lstrcpy(nid.szInfoTitle, szTitle);
if (lpszProxy)
{
nid.uFlags |= NIF_INFO|NIF_TIP;
if (lstrlen(lpszProxy) > 0)
{
lstrcpy(nid.szTip, lpszProxy);
lstrcpy(nid.szInfo, lpszProxy);
}
else
{
lstrcpy(nid.szInfo, szBalloon);
lstrcpy(nid.szTip, szTooltip);
}
}
Shell_NotifyIcon(dwMessage, &nid);
return TRUE;
}
BOOL DeleteTrayIcon()
{
NOTIFYICONDATA nid;
nid.cbSize = (DWORD)sizeof(NOTIFYICONDATA);
nid.hWnd = hWnd;
nid.uID = NID_UID;
Shell_NotifyIcon(NIM_DELETE, &nid);
return TRUE;
}
LPCTSTR GetWindowsProxy()
{
static WCHAR szProxy[1024] = {0};
HKEY hKey;
DWORD dwData = 0;
DWORD dwSize = sizeof(DWORD);
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER,
L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
0,
KEY_READ | 0x0200,
&hKey))
{
szProxy[0] = 0;
dwSize = sizeof(szProxy)/sizeof(szProxy[0]);
RegQueryValueExW(hKey, L"AutoConfigURL", NULL, 0, (LPBYTE)&szProxy, &dwSize);
if (wcslen(szProxy))
{
RegCloseKey(hKey);
return szProxy;
}
dwData = 0;
RegQueryValueExW(hKey, L"ProxyEnable", NULL, 0, (LPBYTE)&dwData, &dwSize);
if (dwData == 0)
{
RegCloseKey(hKey);
return L"";
}
szProxy[0] = 0;
dwSize = sizeof(szProxy)/sizeof(szProxy[0]);
RegQueryValueExW(hKey, L"ProxyServer", NULL, 0, (LPBYTE)&szProxy, &dwSize);
if (wcslen(szProxy))
{
RegCloseKey(hKey);
return szProxy;
}
}
return szProxy;
}
BOOL SetWindowsProxy(WCHAR* szProxy, const WCHAR* szProxyInterface=NULL)
{
INTERNET_PER_CONN_OPTION_LIST conn_options;
BOOL bReturn;
DWORD dwBufferSize = sizeof(conn_options);
if (wcslen(szProxy) == 0)
{
conn_options.dwSize = dwBufferSize;
conn_options.pszConnection = (WCHAR*)szProxyInterface;
conn_options.dwOptionCount = 1;
conn_options.pOptions = (INTERNET_PER_CONN_OPTION*)malloc(sizeof(INTERNET_PER_CONN_OPTION)*conn_options.dwOptionCount);
conn_options.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
conn_options.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT;
}
else if (wcsstr(szProxy, L"://") != NULL)
{
conn_options.dwSize = dwBufferSize;
conn_options.pszConnection = (WCHAR*)szProxyInterface;
conn_options.dwOptionCount = 3;
conn_options.pOptions = (INTERNET_PER_CONN_OPTION*)malloc(sizeof(INTERNET_PER_CONN_OPTION)*conn_options.dwOptionCount);
conn_options.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
conn_options.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT | PROXY_TYPE_AUTO_PROXY_URL;
conn_options.pOptions[1].dwOption = INTERNET_PER_CONN_AUTOCONFIG_URL;
conn_options.pOptions[1].Value.pszValue = szProxy;
conn_options.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
conn_options.pOptions[2].Value.pszValue = L"<local>";
}
else
{
conn_options.dwSize = dwBufferSize;
conn_options.pszConnection = (WCHAR*)szProxyInterface;
conn_options.dwOptionCount = 3;
conn_options.pOptions = (INTERNET_PER_CONN_OPTION*)malloc(sizeof(INTERNET_PER_CONN_OPTION)*conn_options.dwOptionCount);
conn_options.pOptions[0].dwOption = INTERNET_PER_CONN_FLAGS;
conn_options.pOptions[0].Value.dwValue = PROXY_TYPE_DIRECT | PROXY_TYPE_PROXY;
conn_options.pOptions[1].dwOption = INTERNET_PER_CONN_PROXY_SERVER;
conn_options.pOptions[1].Value.pszValue = szProxy;
conn_options.pOptions[2].dwOption = INTERNET_PER_CONN_PROXY_BYPASS;
conn_options.pOptions[2].Value.pszValue = L"<local>";
}
bReturn = InternetSetOption(NULL, INTERNET_OPTION_PER_CONNECTION_OPTION, &conn_options, dwBufferSize);
free(conn_options.pOptions);
InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
InternetSetOption(NULL, INTERNET_OPTION_REFRESH , NULL, 0);
return bReturn;
}
BOOL SetWindowsProxyForAllRasConnections(WCHAR* szProxy)
{
for (LPCSTR lpRasPbk = szRasPbk; *lpRasPbk; lpRasPbk += strlen(lpRasPbk) + 1)
{
char szPath[2048] = "";
if (ExpandEnvironmentStringsA(lpRasPbk, szPath, sizeof(szPath)/sizeof(szPath[0])))
{
char line[2048] = "";
int length = 0;
FILE * fp = fopen(szPath, "r");
if (fp != NULL)
{
while (!feof(fp))
{
if (fgets(line, sizeof(line)/sizeof(line[0])-1, fp))
{
length = strlen(line);
if (length > 3 && line[0] == '[' && line[length-2] == ']')
{
line[length-2] = 0;
WCHAR szSection[64] = L"";
MultiByteToWideChar(CP_UTF8, 0, line+1, -1, szSection, sizeof(szSection)/sizeof(szSection[0]));
SetWindowsProxy(szProxy, szSection);
}
}
}
fclose(fp);
}
}
}
return TRUE;
}
BOOL ShowPopupMenu()
{
POINT pt;
HMENU hSubMenu = NULL;
LPCTSTR lpCurrentProxy = GetWindowsProxy();
if (lpProxyList[1] != NULL)
{
hSubMenu = CreatePopupMenu();
for (int i = 0; lpProxyList[i]; i++)
{
UINT uFlags = wcscmp(lpProxyList[i], lpCurrentProxy) == 0 ? MF_STRING | MF_CHECKED : MF_STRING;
LPCTSTR lpText = wcslen(lpProxyList[i]) ? lpProxyList[i] : L"\x7981\x7528\x4ee3\x7406";
AppendMenu(hSubMenu, uFlags, WM_TASKBARNOTIFY_MENUITEM_PROXYLIST_BASE+i, lpText);
}
}
HMENU hMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING, WM_TASKBARNOTIFY_MENUITEM_SHOW, L"\x663e\x793a");
AppendMenu(hMenu, MF_STRING, WM_TASKBARNOTIFY_MENUITEM_HIDE, L"\x9690\x85cf");
if (hSubMenu != NULL)
{
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT_PTR)hSubMenu, L"\x8bbe\x7f6e IE \x4ee3\x7406");
}
AppendMenu(hMenu, MF_STRING, WM_TASKBARNOTIFY_MENUITEM_RELOAD, L"\x91cd\x65b0\x8f7d\x5165");
AppendMenu(hMenu, MF_STRING, WM_TASKBARNOTIFY_MENUITEM_EXIT, L"\x9000\x51fa");
GetCursorPos(&pt);
TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL);
PostMessage(hWnd, WM_NULL, 0, 0);
if (hSubMenu != NULL)
DestroyMenu(hSubMenu);
DestroyMenu(hMenu);
return TRUE;
}
BOOL ParseProxyList()
{
WCHAR * tmpProxyString = _wcsdup(szProxyString);
ExpandEnvironmentStrings(tmpProxyString, szProxyString, sizeof(szProxyString)/sizeof(szProxyString[0]));
free(tmpProxyString);
WCHAR *sep = L"\n";
WCHAR *pos = wcstok(szProxyString, sep);
INT i = 0;
lpProxyList[i++] = L"";
while (pos && i < sizeof(lpProxyList)/sizeof(lpProxyList[0]))
{
lpProxyList[i++] = pos;
pos = wcstok(NULL, sep);
}
lpProxyList[i] = 0;
for (LPSTR ptr = szRasPbk; *ptr; ptr++)
{
if (*ptr == '\n')
{
*ptr++ = 0;
}
}
return TRUE;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPED|WS_SYSMENU,
NULL, NULL, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
BOOL CDCurrentDirectory()
{
WCHAR szPath[4096] = L"";
GetModuleFileName(NULL, szPath, sizeof(szPath)/sizeof(szPath[0])-1);
*wcsrchr(szPath, L'\\') = 0;
SetCurrentDirectory(szPath);
SetEnvironmentVariableW(L"CWD", szPath);
return TRUE;
}
BOOL SetEenvironment()
{
LoadString(hInst, IDS_CMDLINE, szCommandLine, sizeof(szCommandLine)/sizeof(szCommandLine[0])-1);
LoadString(hInst, IDS_ENVIRONMENT, szEnvironment, sizeof(szEnvironment)/sizeof(szEnvironment[0])-1);
LoadString(hInst, IDS_PROXYLIST, szProxyString, sizeof(szProxyString)/sizeof(szEnvironment[0])-1);
LoadStringA(hInst, IDS_RASPBK, szRasPbk, sizeof(szRasPbk)/sizeof(szRasPbk[0])-1);
WCHAR *sep = L"\n";
WCHAR *pos = NULL;
WCHAR *token = wcstok(szEnvironment, sep);
while(token != NULL)
{
if (pos = wcschr(token, L'='))
{
*pos = 0;
SetEnvironmentVariableW(token, pos+1);
//wprintf(L"[%s] = [%s]\n", token, pos+1);
}
token = wcstok(NULL, sep);
}
GetEnvironmentVariableW(L"TASKBAR_TITLE", szTitle, sizeof(szTitle)/sizeof(szTitle[0])-1);
GetEnvironmentVariableW(L"TASKBAR_TOOLTIP", szTooltip, sizeof(szTooltip)/sizeof(szTooltip[0])-1);
GetEnvironmentVariableW(L"TASKBAR_BALLOON", szBalloon, sizeof(szBalloon)/sizeof(szBalloon[0])-1);
return TRUE;
}
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
char mesg[128];
switch(CEvent)
{
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
case CTRL_CLOSE_EVENT:
SendMessage(hWnd, WM_CLOSE, NULL, NULL);
break;
}
return TRUE;
}
BOOL CreateConsole()
{
WCHAR szVisible[BUFSIZ] = L"";
AllocConsole();
_wfreopen(L"CONIN$", L"r+t", stdin);
_wfreopen(L"CONOUT$", L"w+t", stdout);
hConsole = GetConsoleWindow();
if (GetEnvironmentVariableW(L"TASKBAR_VISIBLE", szVisible, BUFSIZ-1) && szVisible[0] == L'0')
{
ShowWindow(hConsole, SW_HIDE);
}
else
{
SetForegroundWindow(hConsole);
}
if (SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler,TRUE)==FALSE)
{
printf("Unable to install handler!\n");
return FALSE;
}
return TRUE;
}
BOOL ExecCmdline()
{
SetWindowText(hConsole, szTitle);
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = TRUE;
BOOL bRet = CreateProcess(NULL, szCommandLine, NULL, NULL, FALSE, NULL, NULL, NULL, &si, &pi);
if(bRet)
{
dwChildrenPid = MyGetProcessId(pi.hProcess);
}
else
{
wprintf(L"ExecCmdline \"%s\" failed!\n", szCommandLine);
MessageBox(NULL, szCommandLine, L"Error: \x6267\x884c\x547d\x4ee4\x5931\x8d25!", MB_OK);
ExitProcess(0);
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return TRUE;
}
BOOL ReloadCmdline()
{
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwChildrenPid);
if (hProcess)
{
TerminateProcess(hProcess, 0);
}
ShowWindow(hConsole, SW_SHOW);
SetForegroundWindow(hConsole);
wprintf(L"\n\n");
Sleep(200);
ExecCmdline();
return TRUE;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(L"TaskbarCreated");
int nID;
switch (message)
{
case WM_TASKBARNOTIFY:
if (lParam == WM_LBUTTONUP)
{
ShowWindow(hConsole, !IsWindowVisible(hConsole));
SetForegroundWindow(hConsole);
}
else if (lParam == WM_RBUTTONUP)
{
SetForegroundWindow(hWnd);
ShowPopupMenu();
}
break;
case WM_COMMAND:
nID = LOWORD(wParam);
if (nID == WM_TASKBARNOTIFY_MENUITEM_SHOW)
{
ShowWindow(hConsole, SW_SHOW);
SetForegroundWindow(hConsole);
}
else if (nID == WM_TASKBARNOTIFY_MENUITEM_HIDE)
{
ShowWindow(hConsole, SW_HIDE);
}
if (nID == WM_TASKBARNOTIFY_MENUITEM_RELOAD)
{
ReloadCmdline();
}
else if (nID == WM_TASKBARNOTIFY_MENUITEM_ABOUT)
{
MessageBoxW(hWnd, szTooltip, szWindowClass, 0);
}
else if (nID == WM_TASKBARNOTIFY_MENUITEM_EXIT)
{
DeleteTrayIcon();
PostMessage(hConsole, WM_CLOSE, 0, 0);
}
else if (WM_TASKBARNOTIFY_MENUITEM_PROXYLIST_BASE <= nID && nID <= WM_TASKBARNOTIFY_MENUITEM_PROXYLIST_BASE+sizeof(lpProxyList)/sizeof(lpProxyList[0]))
{
WCHAR *szProxy = lpProxyList[nID-WM_TASKBARNOTIFY_MENUITEM_PROXYLIST_BASE];
SetWindowsProxy(szProxy);
SetWindowsProxyForAllRasConnections(szProxy);
ShowTrayIcon(szProxy, NIM_MODIFY);
}
break;
case WM_CLOSE:
DeleteTrayIcon();
PostQuitMessage(0);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
if (message == WM_TASKBARCREATED)
{
ShowTrayIcon(NULL, NIM_ADD);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TASKBAR);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCTSTR)NULL;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR lpCmdLine, int nCmdShow)
{
MSG msg;
hInst = hInstance;
CDCurrentDirectory();
SetEenvironment();
ParseProxyList();
MyRegisterClass(hInstance);
if (!InitInstance (hInstance, SW_HIDE))
{
return FALSE;
}
CreateConsole();
ExecCmdline();
ShowTrayIcon(GetWindowsProxy());
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}