1
- #include <Windows.h>
1
+ #include <Windows.h>
2
2
#include <tchar.h>
3
3
#include <StrSafe.h>
4
4
#include "Global.h"
5
5
#include "EasyWindow.h"
6
6
#include <math.h>
7
7
#include "GaussianBlur.h"
8
+ #include <WinInet.h>
8
9
9
10
11
+ EZWND AccountPage , AppearancePage ,UpdatePage ;
10
12
11
- EZWND AccountPage , AppearancePage ;
13
+
14
+ #define COLOR_GRID_WIDTH 8
15
+ #define COLOR_GRID_HEIGHT 6
16
+
17
+ COLORREF ColorGrid [COLOR_GRID_HEIGHT ][COLOR_GRID_WIDTH ] =
18
+ {
19
+ RGB (255 ,185 ,0 ),RGB (255 ,140 ,0 ),RGB (247 ,99 ,12 ),RGB (202 ,80 ,16 ),RGB (218 ,59 ,1 ),RGB (239 ,105 ,80 ),RGB (209 ,52 ,56 ),RGB (255 ,67 ,67 ),
20
+ RGB (231 ,72 ,86 ),RGB (232 ,17 ,35 ),RGB (234 ,0 ,94 ),RGB (195 ,0 ,82 ),RGB (227 ,0 ,140 ),RGB (191 ,0 ,119 ),RGB (194 ,57 ,179 ),RGB (154 ,0 ,137 ),
21
+ RGB (0 ,120 ,215 ),RGB (0 ,99 ,177 ),RGB (142 ,140 ,216 ),RGB (107 ,105 ,214 ),RGB (135 ,100 ,184 ),RGB (166 ,77 ,169 ),RGB (177 ,70 ,194 ),RGB (136 ,23 ,152 ),
22
+ RGB (0 ,153 ,188 ),RGB (45 ,125 ,154 ),RGB (0 ,183 ,195 ),RGB (3 ,131 ,135 ),RGB (0 ,178 ,148 ),RGB (1 ,133 ,116 ),RGB (0 ,204 ,106 ),RGB (16 ,137 ,62 ),
23
+ RGB (122 ,117 ,116 ),RGB (93 ,90 ,88 ),RGB (104 ,118 ,138 ),RGB (81 ,92 ,107 ),RGB (86 ,124 ,115 ),RGB (72 ,104 ,96 ),RGB (73 ,130 ,5 ),RGB (16 ,124 ,16 ),
24
+ RGB (118 ,118 ,118 ),RGB (76 ,74 ,72 ),RGB (105 ,121 ,126 ),RGB (74 ,84 ,89 ),RGB (100 ,124 ,100 ),RGB (82 ,94 ,84 ),RGB (132 ,117 ,69 ),RGB (126 ,115 ,95 )
25
+ };
12
26
13
27
typedef struct __StngBtn
14
28
{
@@ -18,8 +32,9 @@ typedef struct __StngBtn
18
32
19
33
SETTINGBTN StngBtnInfo [] =
20
34
{
21
- TEXT ("账号" ), & AccountPage ,
22
- TEXT ("外观" ), & AppearancePage ,
35
+ TEXT ("账号" ), & AccountPage ,
36
+ TEXT ("外观" ), & AppearancePage ,
37
+ TEXT ("更新" ),& UpdatePage
23
38
};
24
39
25
40
int SelStng ;
@@ -30,6 +45,8 @@ EZWNDPROC SettingsBtnProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
30
45
31
46
EZWNDPROC AccountPageProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam );
32
47
EZWNDPROC AppearancePageProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam );
48
+ EZWNDPROC ColorBtnProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam );
49
+ EZWNDPROC UpdatePageProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam );
33
50
34
51
EZWNDPROC BasicSettingsProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam )
35
52
{
@@ -54,12 +71,13 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
54
71
55
72
AccountPage = CreateEZWindow (ezWnd , 120 , 0 , ezWnd -> Width - 120 , ezWnd -> Height , AccountPageProc );
56
73
AppearancePage = CreateEZWindow (ezWnd , 120 , 0 , ezWnd -> Width - 120 , ezWnd -> Height , AppearancePageProc );
57
-
74
+ UpdatePage = CreateEZWindow ( ezWnd , 120 , 0 , ezWnd -> Width - 120 , ezWnd -> Height , UpdatePageProc );
58
75
AppearancePage -> ShowState = 2 ;
59
76
AppearancePage -> MouseMsgRecv = 2 ;
60
-
77
+ UpdatePage -> ShowState = 2 ;
78
+ UpdatePage -> MouseMsgRecv = 2 ;
61
79
break ;
62
- case EZWM_COMMAND ://lParam附加按钮ID
80
+ case EZWM_COMMAND ://lParam附加按钮ID
63
81
64
82
(* (StngBtnInfo [SelStng ].Page ))-> ShowState = 2 ;
65
83
(* (StngBtnInfo [SelStng ].Page ))-> MouseMsgRecv = 2 ;
@@ -75,7 +93,7 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
75
93
break ;
76
94
case EZWM_TRANSDRAW :
77
95
PatBlt (ShadowDC , 0 , 0 , 220 , ezWnd -> Height + 100 , BLACKNESS );
78
- //修改透明层
96
+ //修改透明层
79
97
{
80
98
81
99
HBITMAP hSel = SelectObject (ShadowDC , CreateCompatibleBitmap (ShadowDC , 1 , 1 ));
@@ -125,14 +143,14 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
125
143
}
126
144
break ;
127
145
case EZWM_TIMER :
128
- //枚举每个按钮检查位置,都就位了就关计时器
146
+ //枚举每个按钮检查位置,都就位了就关计时器
129
147
{
130
148
BOOL bSet = 1 ;
131
149
for (int i = 0 ; i < _countof (StngBtnInfo ); i ++ )
132
150
{
133
151
if (SelStng == i )
134
152
{
135
- //左基准25
153
+ //左基准25
136
154
if (StngBtn [i ]-> x != 25 )
137
155
{
138
156
bSet = 0 ;
@@ -143,7 +161,7 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
143
161
}
144
162
else
145
163
{
146
- //左基准35
164
+ //左基准35
147
165
if (StngBtn [i ]-> x != 35 )
148
166
{
149
167
bSet = 0 ;
@@ -212,26 +230,26 @@ EZWNDPROC AccountPageProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
212
230
switch (message )
213
231
{
214
232
case EZWM_CREATE :
215
- TitleStatic = CreateEZStyleWindow (ezWnd , TEXT ("校园网账号" ), EZS_CHILD | EZS_STATIC , 50 , 30 , ezWnd -> Width , 60 );
233
+ TitleStatic = CreateEZStyleWindow (ezWnd , TEXT ("校园网账号" ), EZS_CHILD | EZS_STATIC , 50 , 30 , ezWnd -> Width , 60 );
216
234
FontForm .lfHeight = 60 * (4.0 / 7.0 );
217
235
EZSendMessage (TitleStatic , EZWM_SETTEXTALIGN , DT_LEFT , 0 );
218
236
EZSendMessage (TitleStatic , EZWM_SETFONT , 0 , & FontForm );
219
237
TitleStatic -> Transparent = 0 ;
220
238
221
- AccountUsageStatic = CreateEZStyleWindow (ezWnd , TEXT ("该账号用于登陆校园网并获取作业,暂不支持教师账号。" ), EZS_CHILD | EZS_STATIC , 50 , 80 , ezWnd -> Width , 30 );
222
- FontForm .lfHeight = 30 * (4.0 / 7.0 );
239
+ AccountUsageStatic = CreateEZStyleWindow (ezWnd , TEXT ("该账号用于登陆校园网并获取作业,不会用于其他用途。 暂不支持教师账号。" ), EZS_CHILD | EZS_STATIC , 50 , 80 , ezWnd -> Width , 35 );
240
+ FontForm .lfHeight = 35 * (4.0 / 7.0 );
223
241
EZSendMessage (AccountUsageStatic , EZWM_SETTEXTALIGN , DT_LEFT , 0 );
224
242
EZSendMessage (AccountUsageStatic , EZWM_SETFONT , 0 , & FontForm );
225
- EZSendMessage (AccountUsageStatic , EZWM_SETCOLOR , RGB (0 , 0 , 0 ), RGB (180 , 180 , 180 ));
243
+ EZSendMessage (AccountUsageStatic , EZWM_SETCOLOR , RGB (0 , 0 , 0 ), RGB (160 , 160 , 160 ));
226
244
AccountUsageStatic -> Transparent = 0 ;
227
245
228
246
229
247
FontForm .lfHeight = 30 * (6.0 / 7.0 );
230
- UserNameText = CreateEZStyleWindow (ezWnd , TEXT ("用户名:" ), EZS_CHILD | EZS_STATIC , 50 , 125 , 90 , 30 );
248
+ UserNameText = CreateEZStyleWindow (ezWnd , TEXT ("用户名:" ), EZS_CHILD | EZS_STATIC , 50 , 125 , 90 , 30 );
231
249
EZSendMessage (UserNameText , EZWM_SETFONT , 0 , & FontForm );
232
250
EZSendMessage (UserNameText , EZWM_SETTEXTALIGN , DT_LEFT | DT_VCENTER | DT_SINGLELINE , 0 );
233
251
UserNameText -> Transparent = 0 ;
234
- PasswdText = CreateEZStyleWindow (ezWnd , TEXT ("密码:" ), EZS_CHILD | EZS_STATIC , 50 , 170 , 90 , 30 );
252
+ PasswdText = CreateEZStyleWindow (ezWnd , TEXT ("密码:" ), EZS_CHILD | EZS_STATIC , 50 , 170 , 90 , 30 );
235
253
EZSendMessage (PasswdText , EZWM_SETFONT , 0 , & FontForm );
236
254
EZSendMessage (PasswdText , EZWM_SETTEXTALIGN , DT_LEFT | DT_VCENTER | DT_SINGLELINE , 0 );
237
255
PasswdText -> Transparent = 0 ;
@@ -243,20 +261,19 @@ EZWNDPROC AccountPageProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
243
261
EZSendMessage (PasswdEdit , EZWM_SETFONT , 0 , & FontForm );
244
262
EZSendMessage (PasswdEdit , EZWM_SETMAXTEXT , 18 , 0 );
245
263
246
- SaveBtn = CreateEZStyleWindow (ezWnd , TEXT ("保存" ), EZS_CHILD | EZS_BUTTON , 202 , 215 , 130 , 40 );
264
+ SaveBtn = CreateEZStyleWindow (ezWnd , TEXT ("保存" ), EZS_CHILD | EZS_BUTTON , 202 , 215 , 130 , 40 );
247
265
EZSendMessage (SaveBtn , EZWM_SETFONT , 0 , & FontForm );
248
266
EZSendMessage (SaveBtn , EZWM_SETCOLOR , RGB (0 , 0 , 0 ), RGB (0 , 0 , 0 ));
249
- SettingsRead ();
267
+
250
268
EZSendMessage (UserNameEdit , EZWM_SETTEXT , PlatformUsername , 0 );
251
269
EZSendMessage (PasswdEdit , EZWM_SETTEXT , PlatformPassword , 0 );
252
270
253
- //读取配置,填入
271
+ //读取配置,填入
254
272
break ;
255
273
case EZWM_COMMAND :
256
274
if (lParam == SaveBtn )
257
275
{
258
- //写入注册表,写入全局变量。
259
- //MessageBox(0, TEXT(""), PasswdEdit->Extend->Title,0);
276
+ //写入注册表,写入全局变量。
260
277
lstrcpy (PlatformUsername , UserNameEdit -> Extend -> Title );
261
278
lstrcpy (PlatformPassword , PasswdEdit -> Extend -> Title );
262
279
SettingsWrite ();
@@ -287,14 +304,163 @@ EZWNDPROC AccountPageProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
287
304
EZWNDPROC AppearancePageProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam )
288
305
{
289
306
static EZWND TitleStatic ;
307
+ static EZWND ColorBtn [COLOR_GRID_HEIGHT ][COLOR_GRID_WIDTH ];
308
+ switch (message )
309
+ {
310
+ case EZWM_CREATE :
311
+ TitleStatic = CreateEZStyleWindow (ezWnd , TEXT ("外观设置" ), EZS_CHILD | EZS_STATIC , 50 , 30 , ezWnd -> Width , 60 );
312
+ FontForm .lfHeight = 60 * (4.0 / 7.0 );
313
+ EZSendMessage (TitleStatic , EZWM_SETTEXTALIGN , DT_LEFT , 0 );
314
+ EZSendMessage (TitleStatic , EZWM_SETFONT , 0 , & FontForm );
315
+ TitleStatic -> Transparent = 0 ;
316
+ for (int y = 0 ; y < COLOR_GRID_HEIGHT ; y ++ )
317
+ {
318
+ for (int x = 0 ; x < COLOR_GRID_WIDTH ; x ++ )
319
+ {
320
+ ColorBtn [y ][x ] = CreateEZWindow (ezWnd , 50 + x * 47 , 110 + y * 47 , 44 , 44 , ColorBtnProc );
321
+ ColorBtn [y ][x ]-> ezID = y * COLOR_GRID_WIDTH + x ;
322
+ //EZSendMessage(ColorBtn[y][x], EZWM_USER_NOTIFY, 0, 0);
323
+ }
324
+ }
325
+ break ;
326
+ case EZWM_COMMAND :
327
+ APP_COLOR = ColorGrid [((EZWND )lParam )-> ezID / COLOR_GRID_WIDTH ][((EZWND )lParam )-> ezID % COLOR_GRID_WIDTH ];
328
+ GDIObjectClean ();
329
+ GDIObjectCreate ();
330
+ EZRepaint (ezWnd -> ezRootParent , 0 );
331
+ //把颜色往注册表里存
332
+ SettingsWrite ();
333
+ break ;
334
+ }
335
+ }
336
+
337
+ EZWNDPROC ColorBtnProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam )
338
+ {
290
339
switch (message )
291
340
{
292
341
case EZWM_DRAW :
293
- TitleStatic = CreateEZStyleWindow (ezWnd , TEXT ("外观设置" ), EZS_CHILD | EZS_STATIC , 50 , 30 , ezWnd -> Width , 200 );
342
+ {
343
+ HBRUSH hBrush = CreateSolidBrush (ColorGrid [ezWnd -> ezID / COLOR_GRID_WIDTH ][ezWnd -> ezID % COLOR_GRID_WIDTH ]);
344
+ SelectObject (wParam , hBrush );
345
+ PatBlt (wParam , 0 , 0 , ezWnd -> Width , ezWnd -> Height , PATCOPY );
346
+ DeleteBrush (hBrush );
347
+ break ;
348
+ }
349
+ case EZWM_LBUTTONUP :
350
+ {
351
+ EZSendMessage (ezWnd -> ezParent , EZWM_COMMAND , 0 , ezWnd );
352
+ break ;
353
+ }
354
+ }
355
+ }
356
+
357
+ EZWNDPROC UpdatePageProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam )
358
+ {
359
+ static EZWND TitleStatic , UpdateBtn ;
360
+ switch (message )
361
+ {
362
+ case EZWM_CREATE :
363
+ TitleStatic = CreateEZStyleWindow (ezWnd , TEXT ("更新" ), EZS_CHILD | EZS_STATIC , 50 , 30 , ezWnd -> Width , 60 );
294
364
FontForm .lfHeight = 60 * (4.0 / 7.0 );
295
365
EZSendMessage (TitleStatic , EZWM_SETTEXTALIGN , DT_LEFT , 0 );
296
366
EZSendMessage (TitleStatic , EZWM_SETFONT , 0 , & FontForm );
297
367
TitleStatic -> Transparent = 0 ;
368
+
369
+ FontForm .lfHeight = 40 * (4.0 / 7.0 );
370
+ UpdateBtn = CreateEZStyleWindow (ezWnd , TEXT ("检查更新并下载" ), EZS_CHILD | EZS_BUTTON , 50 , 100 , 180 , 40 );
371
+ EZSendMessage (UpdateBtn , EZWM_SETCOLOR , RGB (0 ,0 ,0 ), RGB (0 , 0 , 0 ));
372
+ EZSendMessage (UpdateBtn , EZWM_SETFONT , 0 , & FontForm );
373
+ break ;
374
+ case EZWM_COMMAND :
375
+ {
376
+ HINTERNET InternetGlobal = 0 , InetUpdateCheck = 0 ,InternetUpdate = 0 ;
377
+ HFILE UpdateFile = 0 ;
378
+ DWORD num , tnum = 0 ;
379
+ BOOL bSuccess = 0 ;
380
+ BOOL bHaveUpdate = 0 ;
381
+ __try
382
+ {
383
+ InternetGlobal = InternetOpenW (L"Homework Viewer" , INTERNET_OPEN_TYPE_DIRECT , NULL , NULL , 0 );
384
+ if (!InternetGlobal )__leave;
385
+
386
+ InetUpdateCheck = InternetOpenUrl (InternetGlobal , TEXT ("http://118.25.77.58/HomeworkViewer/update.txt" ), 0 , 0 , INTERNET_FLAG_NEED_FILE , 0 );
387
+ if (!InetUpdateCheck )__leave;
388
+
389
+ char UpdateVer [16 ] = { 0 };
390
+ InternetReadFile (InetUpdateCheck , UpdateVer , 10 , & num );
391
+ if (!num )
392
+ {
393
+ __leave;
394
+ }
395
+ double ver ;
396
+ sscanf_s (UpdateVer , "%lf" , & ver );
397
+
398
+ if (ver <= lfVersion )
399
+ {
400
+ MessageBox (NULL , TEXT ("看上去好像没什么可以更新的 ╮( •́ω•̀ )╭" ), szAppName , MB_TASKMODAL );
401
+ bSuccess = 1 ;
402
+ __leave;
403
+ }
404
+ bHaveUpdate = 1 ;
405
+ InternetUpdate = InternetOpenUrl (InternetGlobal , TEXT ("http://118.25.77.58/HomeworkViewer/Homework%20Viewer.exe" ), 0 , 0 , INTERNET_FLAG_NEED_FILE , 0 );
406
+ if (!InternetUpdate )__leave;
407
+
408
+
409
+ CHAR Buffer [1024 ];
410
+ DWORD Readed ;
411
+
412
+ //打开文件
413
+ UpdateFile = CreateFile (TEXT ("Homework Viewer.exe" ), GENERIC_ALL , 0 , 0 , CREATE_NEW , FILE_ATTRIBUTE_NORMAL , 0 );
414
+ if (!UpdateFile )__leave;
415
+
416
+ BOOL bRet = 0 ;
417
+
418
+ DWORD Written ;
419
+ do
420
+ {
421
+ bRet = InternetReadFile (InternetUpdate , Buffer , 1024 , & num );
422
+ tnum += num ;
423
+ WriteFile (UpdateFile , Buffer , num , & Written , 0 );
424
+
425
+ } while (!(bRet && num == 0 ));
426
+ bSuccess = 1 ;
427
+
428
+ }
429
+ __finally
430
+ {
431
+ if (InternetGlobal )InternetCloseHandle (InternetGlobal );
432
+ if (InetUpdateCheck )InternetCloseHandle (InetUpdateCheck );
433
+ if (InternetUpdate )InternetCloseHandle (InternetUpdate );
434
+
435
+ if (UpdateFile )
436
+ {
437
+ //TODO:句柄关了,文件删掉了没?
438
+ CloseHandle (UpdateFile );
439
+ }
440
+
441
+
442
+ if (!bSuccess )
443
+ {
444
+ MessageBox (NULL , TEXT ("更新失败" ), szAppName , MB_TASKMODAL );
445
+ }
446
+ else if (bHaveUpdate )
447
+ {
448
+ //启动进程,关闭自身
449
+ STARTUPINFO si = { 0 };
450
+ si .cb = sizeof (STARTUPINFO );
451
+
452
+ PROCESS_INFORMATION pi = { 0 };
453
+
454
+ MessageBox (NULL , TEXT ("更新完毕" ), szAppName , MB_TASKMODAL );
455
+ CreateProcess (TEXT ("Homework Viewer.exe" ), NULL , 0 , 0 , 0 , 0 , 0 , 0 , & si , & pi );
456
+ CloseHandle (pi .hProcess );
457
+ CloseHandle (pi .hThread );
458
+ PostQuitMessage (0 );
459
+ }
460
+ }
461
+ }
298
462
break ;
299
463
}
300
- }
464
+ }
465
+
466
+
0 commit comments