1- #include <Windows.h>
1+ #include <Windows.h>
22#include <tchar.h>
33#include <StrSafe.h>
44#include "Global.h"
55#include "EasyWindow.h"
66#include <math.h>
77#include "GaussianBlur.h"
8+ #include <WinInet.h>
89
910
11+ EZWND AccountPage , AppearancePage ,UpdatePage ;
1012
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+ };
1226
1327typedef struct __StngBtn
1428{
@@ -18,8 +32,9 @@ typedef struct __StngBtn
1832
1933SETTINGBTN StngBtnInfo [] =
2034{
21- TEXT ("账号" ), & AccountPage ,
22- TEXT ("外观" ), & AppearancePage ,
35+ TEXT ("账号" ), & AccountPage ,
36+ TEXT ("外观" ), & AppearancePage ,
37+ TEXT ("更新" ),& UpdatePage
2338};
2439
2540int SelStng ;
@@ -30,6 +45,8 @@ EZWNDPROC SettingsBtnProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
3045
3146EZWNDPROC AccountPageProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam );
3247EZWNDPROC 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 );
3350
3451EZWNDPROC BasicSettingsProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam )
3552{
@@ -54,12 +71,13 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
5471
5572 AccountPage = CreateEZWindow (ezWnd , 120 , 0 , ezWnd -> Width - 120 , ezWnd -> Height , AccountPageProc );
5673 AppearancePage = CreateEZWindow (ezWnd , 120 , 0 , ezWnd -> Width - 120 , ezWnd -> Height , AppearancePageProc );
57-
74+ UpdatePage = CreateEZWindow ( ezWnd , 120 , 0 , ezWnd -> Width - 120 , ezWnd -> Height , UpdatePageProc );
5875 AppearancePage -> ShowState = 2 ;
5976 AppearancePage -> MouseMsgRecv = 2 ;
60-
77+ UpdatePage -> ShowState = 2 ;
78+ UpdatePage -> MouseMsgRecv = 2 ;
6179 break ;
62- case EZWM_COMMAND ://lParam附加按钮ID
80+ case EZWM_COMMAND ://lParam附加按钮ID
6381
6482 (* (StngBtnInfo [SelStng ].Page ))-> ShowState = 2 ;
6583 (* (StngBtnInfo [SelStng ].Page ))-> MouseMsgRecv = 2 ;
@@ -75,7 +93,7 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
7593 break ;
7694 case EZWM_TRANSDRAW :
7795 PatBlt (ShadowDC , 0 , 0 , 220 , ezWnd -> Height + 100 , BLACKNESS );
78- //修改透明层
96+ //修改透明层
7997 {
8098
8199 HBITMAP hSel = SelectObject (ShadowDC , CreateCompatibleBitmap (ShadowDC , 1 , 1 ));
@@ -125,14 +143,14 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
125143 }
126144 break ;
127145 case EZWM_TIMER :
128- //枚举每个按钮检查位置,都就位了就关计时器
146+ //枚举每个按钮检查位置,都就位了就关计时器
129147 {
130148 BOOL bSet = 1 ;
131149 for (int i = 0 ; i < _countof (StngBtnInfo ); i ++ )
132150 {
133151 if (SelStng == i )
134152 {
135- //左基准25
153+ //左基准25
136154 if (StngBtn [i ]-> x != 25 )
137155 {
138156 bSet = 0 ;
@@ -143,7 +161,7 @@ EZWNDPROC BasicSettingsProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lPar
143161 }
144162 else
145163 {
146- //左基准35
164+ //左基准35
147165 if (StngBtn [i ]-> x != 35 )
148166 {
149167 bSet = 0 ;
@@ -212,26 +230,26 @@ EZWNDPROC AccountPageProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
212230 switch (message )
213231 {
214232 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 );
216234 FontForm .lfHeight = 60 * (4.0 / 7.0 );
217235 EZSendMessage (TitleStatic , EZWM_SETTEXTALIGN , DT_LEFT , 0 );
218236 EZSendMessage (TitleStatic , EZWM_SETFONT , 0 , & FontForm );
219237 TitleStatic -> Transparent = 0 ;
220238
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 );
223241 EZSendMessage (AccountUsageStatic , EZWM_SETTEXTALIGN , DT_LEFT , 0 );
224242 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 ));
226244 AccountUsageStatic -> Transparent = 0 ;
227245
228246
229247 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 );
231249 EZSendMessage (UserNameText , EZWM_SETFONT , 0 , & FontForm );
232250 EZSendMessage (UserNameText , EZWM_SETTEXTALIGN , DT_LEFT | DT_VCENTER | DT_SINGLELINE , 0 );
233251 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 );
235253 EZSendMessage (PasswdText , EZWM_SETFONT , 0 , & FontForm );
236254 EZSendMessage (PasswdText , EZWM_SETTEXTALIGN , DT_LEFT | DT_VCENTER | DT_SINGLELINE , 0 );
237255 PasswdText -> Transparent = 0 ;
@@ -243,20 +261,19 @@ EZWNDPROC AccountPageProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
243261 EZSendMessage (PasswdEdit , EZWM_SETFONT , 0 , & FontForm );
244262 EZSendMessage (PasswdEdit , EZWM_SETMAXTEXT , 18 , 0 );
245263
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 );
247265 EZSendMessage (SaveBtn , EZWM_SETFONT , 0 , & FontForm );
248266 EZSendMessage (SaveBtn , EZWM_SETCOLOR , RGB (0 , 0 , 0 ), RGB (0 , 0 , 0 ));
249- SettingsRead ();
267+
250268 EZSendMessage (UserNameEdit , EZWM_SETTEXT , PlatformUsername , 0 );
251269 EZSendMessage (PasswdEdit , EZWM_SETTEXT , PlatformPassword , 0 );
252270
253- //读取配置,填入
271+ //读取配置,填入
254272 break ;
255273 case EZWM_COMMAND :
256274 if (lParam == SaveBtn )
257275 {
258- //写入注册表,写入全局变量。
259- //MessageBox(0, TEXT(""), PasswdEdit->Extend->Title,0);
276+ //写入注册表,写入全局变量。
260277 lstrcpy (PlatformUsername , UserNameEdit -> Extend -> Title );
261278 lstrcpy (PlatformPassword , PasswdEdit -> Extend -> Title );
262279 SettingsWrite ();
@@ -287,14 +304,163 @@ EZWNDPROC AccountPageProc(EZWND ezWnd, int message, WPARAM wParam, LPARAM lParam
287304EZWNDPROC AppearancePageProc (EZWND ezWnd , int message , WPARAM wParam , LPARAM lParam )
288305{
289306 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+ {
290339 switch (message )
291340 {
292341 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 );
294364 FontForm .lfHeight = 60 * (4.0 / 7.0 );
295365 EZSendMessage (TitleStatic , EZWM_SETTEXTALIGN , DT_LEFT , 0 );
296366 EZSendMessage (TitleStatic , EZWM_SETFONT , 0 , & FontForm );
297367 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+ }
298462 break ;
299463 }
300- }
464+ }
465+
466+
0 commit comments