From 5d09d0f7b0c78a4d946c175b9e4615dae31de58d Mon Sep 17 00:00:00 2001 From: CGDF <17256673+CGDF-Github@users.noreply.github.com> Date: Tue, 11 Dec 2018 19:35:05 +0800 Subject: [PATCH] update to 1.2.4 --- .../Dialog/Dialog_Main/Dialog_Main.cpp | 194 ++++++++---------- .../NetSpeed/Dialog/Dialog_Main/Dialog_Main.h | 18 +- .../Dialog/Dialog_Setting/Dialog_Setting.cpp | 148 ++++++------- .../Dialog/Dialog_Setting/Dialog_Setting.h | 6 +- NetSpeed/NetSpeed/Main.cpp | 16 +- NetSpeed/NetSpeed/Main.h | 4 +- NetSpeed/NetSpeed/Menu/Menu.cpp | 15 +- NetSpeed/NetSpeed/NetSpeed.vcxproj | 2 +- NetSpeed/NetSpeed/Registry/Registry.cpp | 79 +++---- NetSpeed/NetSpeed/Registry/Registry.h | 6 +- NetSpeed/NetSpeed/Resource/NetSpeed.rc | Bin 10070 -> 10070 bytes NetSpeed/NetSpeed/Text/Text.cpp | 94 ++++----- NetSpeed/NetSpeed/Text/Text.h | 46 +++-- .../NetSpeed/Timer_Refresh/Timer_Refresh.cpp | 145 +++++++------ .../NetSpeed/Timer_Refresh/Timer_Refresh.h | 13 +- 15 files changed, 371 insertions(+), 415 deletions(-) diff --git a/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.cpp b/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.cpp index 393a0bb..81558a6 100644 --- a/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.cpp +++ b/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.cpp @@ -5,87 +5,76 @@ #include "../../NotifyIcon/NotifyIcon.h" #include "../../Registry/Registry.h" #include "../../Resource/resource.h" +#include "../../Text/Text.h" #include "../Dialog_Setting/Dialog_Setting.h" -HBRUSH Dialog_Main::Bursh_Background_ = NULL; -HBRUSH Dialog_Main::Bursh_Text_ = NULL; COLORREF Dialog_Main::Color_Background_; COLORREF Dialog_Main::Color_Text_; -HFONT Dialog_Main::Font_Text_ = NULL; -LONG Dialog_Main::Origin_Height_Dialog_; -LONG Dialog_Main::Origin_Height_Text_; -LONG Dialog_Main::Origin_Width_Dialog_; -LONG Dialog_Main::Origin_Width_Text_; -HPEN Dialog_Main::Pen_Background_ = NULL; +LONG Dialog_Main::DialogOriginHeight_; +LONG Dialog_Main::DialogOriginWidth_; +HBRUSH Dialog_Main::Handle_Bursh_Background_ = NULL; +HBRUSH Dialog_Main::Handle_Bursh_Text_ = NULL; +HFONT Dialog_Main::Handle_Font_Text_ = NULL; +HPEN Dialog_Main::Handle_Pen_Background_ = NULL; +LONG Dialog_Main::TextOriginHeight_; +LONG Dialog_Main::TextOriginWidth_; //public: -INT_PTR Dialog_Main::Process(HWND Handle_Dialog, UINT Message_Dialog, WPARAM Param_WORD, LPARAM Param_LONG) { +INT_PTR Dialog_Main::Process(HWND Handle_Dialog, UINT DialogMessage, WPARAM ParamWORD, LPARAM ParamLONG) { Dialog_Main::Handle_Set(Handle_Dialog); - BOOL Result_Process = TRUE; - switch (Message_Dialog) { - case WM_COMMAND: - { - switch (LOWORD(Param_WORD)) { - case WM_MENU_EXIT: - { + BOOL ProcessResult = TRUE; + switch (DialogMessage) { + case WM_COMMAND: { + switch (LOWORD(ParamWORD)) { + case WM_MENU_EXIT: { Menu::Item_Exit(); break; } - case WM_MENU_SETTING: - { + case WM_MENU_SETTING: { Menu::Item_Setting(); break; } - case WM_MENU_SHOW: - { + case WM_MENU_SHOW: { Menu::Item_Show(); break; } - case WM_MENU_STARTUP: - { + case WM_MENU_STARTUP: { Menu::Item_Startup(); break; } - default: - { - Result_Process = FALSE; + default: { + ProcessResult = FALSE; break; } } break; } - case WM_CTLCOLORDLG: - { - return (INT_PTR)Bursh_Background_; + case WM_CTLCOLORDLG: { + return (INT_PTR)Handle_Bursh_Background_; } - case WM_CTLCOLORSTATIC: - { - SetBkMode((HDC)Param_WORD, TRANSPARENT); - SetTextColor((HDC)Param_WORD, Color_Text_); - return (INT_PTR)Bursh_Background_; + case WM_CTLCOLORSTATIC: { + SetBkMode((HDC)ParamWORD, TRANSPARENT); + SetTextColor((HDC)ParamWORD, Color_Text_); + return (INT_PTR)Handle_Bursh_Background_; } - case WM_DESTROY: - { + case WM_DESTROY: { NotifyIcon::Destroy(); return 0; } - case WM_ERASEBKGND: - { - RECT Rect_Dialog; - SelectObject((HDC)Param_WORD, Pen_Background_); - SelectObject((HDC)Param_WORD, Bursh_Background_); - GetClientRect(Handle_Dialog, &Rect_Dialog); - Rectangle((HDC)Param_WORD, Rect_Dialog.left, Rect_Dialog.top, Rect_Dialog.right, Rect_Dialog.bottom); + case WM_ERASEBKGND: { + RECT DialogRect; + SelectObject((HDC)ParamWORD, Handle_Pen_Background_); + SelectObject((HDC)ParamWORD, Handle_Bursh_Background_); + GetClientRect(Handle_Dialog, &DialogRect); + Rectangle((HDC)ParamWORD, DialogRect.left, DialogRect.top, DialogRect.right, DialogRect.bottom); break; } - case WM_EXITSIZEMOVE: - { + case WM_EXITSIZEMOVE: { Registry::Position_Set(Position_Get()); break; } - case WM_INITDIALOG: - { + case WM_INITDIALOG: { Color_Background_ = Registry::ColorBackground_Get(); Color_Text_ = Registry::ColorText_Get(); Dialog_Main::ColorBackground_Set(Color_Background_); @@ -102,76 +91,67 @@ INT_PTR Dialog_Main::Process(HWND Handle_Dialog, UINT Message_Dialog, WPARAM Par INT Transparency = Registry::Transparency_Get(); Dialog_Main::Transparency_Set(Transparency); - RECT Rect_Dialog; - GetWindowRect(Handle_Dialog, &Rect_Dialog); - Origin_Height_Dialog_ = Rect_Dialog.bottom - Rect_Dialog.top; - Origin_Width_Dialog_ = Rect_Dialog.right - Rect_Dialog.left; - RECT Rect_Text; - GetWindowRect(GetDlgItem(Handle_Dialog, ID_Static_Upload), &Rect_Text); - Origin_Height_Text_ = Rect_Text.bottom - Rect_Text.top; - Origin_Width_Text_ = Rect_Text.right - Rect_Text.left; + RECT DialogRect; + GetWindowRect(Handle_Dialog, &DialogRect); + DialogOriginHeight_ = DialogRect.bottom - DialogRect.top; + DialogOriginWidth_ = DialogRect.right - DialogRect.left; + RECT TextRect; + GetWindowRect(GetDlgItem(Handle_Dialog, ID_Static_Upload), &TextRect); + TextOriginHeight_ = TextRect.bottom - TextRect.top; + TextOriginWidth_ = TextRect.right - TextRect.left; INT Size = Registry::Size_Get(); Dialog_Main::Size_Set(Size); - SetParent(Dialog_Main::Handle_Get(), NULL); - Timer_Refresh::Init(); Timer_Refresh::Start(); break; } - case WM_LBUTTONDOWN: - { - SendMessageW(Handle_Dialog, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(LOWORD(Param_LONG), HIWORD(Param_LONG))); + case WM_LBUTTONDOWN: { + SendMessageW(Handle_Dialog, WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(LOWORD(ParamLONG), HIWORD(ParamLONG))); break; } - case WM_NCPAINT: - { + case WM_NCPAINT: { NotifyIcon::Init(); break; } - case WM_NOTIFYICON: - { - switch (Param_LONG) { - case WM_RBUTTONUP: - { + case WM_NOTIFYICON: { + switch (ParamLONG) { + case WM_RBUTTONUP: { Menu::Pop(); return TRUE; } - default: - { - Result_Process = FALSE; + default: { + ProcessResult = FALSE; break; } } break; } - case WM_RBUTTONUP: - { + case WM_RBUTTONUP: { Menu::Pop(); break; } - default: - { - Result_Process = FALSE; + default: { + ProcessResult = FALSE; break; } } - return Result_Process; + return ProcessResult; } //public: VOID Dialog_Main::ColorBackground_Set(COLORREF Background_Color) { Color_Background_ = Background_Color; - if (Bursh_Background_ != NULL) { - DeleteObject(Bursh_Background_); + if (Handle_Bursh_Background_ != NULL) { + DeleteObject(Handle_Bursh_Background_); } - if (Pen_Background_ != NULL) { - DeleteObject(Pen_Background_); + if (Handle_Pen_Background_ != NULL) { + DeleteObject(Handle_Pen_Background_); } - Bursh_Background_ = CreateSolidBrush(Color_Background_); - Pen_Background_ = CreatePen(PS_SOLID, 0, Color_Background_); + Handle_Bursh_Background_ = CreateSolidBrush(Color_Background_); + Handle_Pen_Background_ = CreatePen(PS_SOLID, 0, Color_Background_); InvalidateRect(Dialog_Main::Handle_Get(), NULL, TRUE); } @@ -181,14 +161,14 @@ VOID Dialog_Main::ColorText_Set(COLORREF Text_Color) { } POINT Dialog_Main::Position_Get() { - RECT Position_RECT; + RECT PositionRect; HWND Handle_Dialog = Dialog_Main::Handle_Get(); - GetWindowRect(Handle_Dialog, &Position_RECT); - MapWindowPoints(HWND_DESKTOP, GetParent(Handle_Dialog), (LPPOINT)&Position_RECT, sizeof(RECT) / sizeof(POINT)); - POINT Position_POINT; - Position_POINT.x = Position_RECT.left; - Position_POINT.y = Position_RECT.top; - return Position_POINT; + GetWindowRect(Handle_Dialog, &PositionRect); + MapWindowPoints(HWND_DESKTOP, GetParent(Handle_Dialog), (LPPOINT)&PositionRect, sizeof(RECT) / sizeof(POINT)); + POINT PositionPoint; + PositionPoint.x = PositionRect.left; + PositionPoint.y = PositionRect.top; + return PositionPoint; } VOID Dialog_Main::Position_Set(POINT Position) { @@ -213,28 +193,28 @@ VOID Dialog_Main::Show_Set(BOOL Show) { } VOID Dialog_Main::Size_Set(INT Size) { - LOGFONTW Font_Info; - ZeroMemory(&Font_Info, sizeof(LOGFONTW)); + LOGFONTW FontInfo; + ZeroMemory(&FontInfo, sizeof(LOGFONTW)); HWND Handle_Dialog = Dialog_Main::Handle_Get(); HDC Handle_DC = GetDC(NULL); - Font_Info.lfHeight = -MulDiv(Size, GetDeviceCaps(Handle_DC, LOGPIXELSY), 72); - wcscpy_s(Font_Info.lfFaceName, LF_FACESIZE, L"Consolas"); - Font_Info.lfWeight = 400; - if (Font_Text_ != NULL) { - DeleteObject(Font_Text_); + FontInfo.lfHeight = -MulDiv(Size, GetDeviceCaps(Handle_DC, LOGPIXELSY), 72); + wcscpy_s(FontInfo.lfFaceName, LF_FACESIZE, L"Consolas"); + FontInfo.lfWeight = 400; + if (Handle_Font_Text_ != NULL) { + DeleteObject(Handle_Font_Text_); } - Font_Text_ = CreateFontIndirectW(&Font_Info); + Handle_Font_Text_ = CreateFontIndirectW(&FontInfo); ReleaseDC(NULL, Handle_DC); - SendDlgItemMessageW(Handle_Dialog, ID_Static_Download, WM_SETFONT, (WPARAM)Font_Text_, TRUE); - SendDlgItemMessageW(Handle_Dialog, ID_Static_Upload, WM_SETFONT, (WPARAM)Font_Text_, TRUE); + SendDlgItemMessageW(Handle_Dialog, ID_Static_Download, WM_SETFONT, (WPARAM)Handle_Font_Text_, TRUE); + SendDlgItemMessageW(Handle_Dialog, ID_Static_Upload, WM_SETFONT, (WPARAM)Handle_Font_Text_, TRUE); SetWindowPos( Handle_Dialog, NULL, NULL, NULL, - Origin_Width_Dialog_ * Size / 12, - Origin_Height_Dialog_ * Size / 12, + DialogOriginWidth_ * Size / 12, + DialogOriginHeight_ * Size / 12, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); SetWindowPos( @@ -242,29 +222,29 @@ VOID Dialog_Main::Size_Set(INT Size) { NULL, NULL, NULL, - Origin_Width_Text_*Size / 12, - Origin_Height_Text_*Size / 12, + TextOriginWidth_*Size / 12, + TextOriginHeight_*Size / 12, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); SetWindowPos( GetDlgItem(Handle_Dialog, ID_Static_Upload), NULL, - Origin_Width_Dialog_ * Size / 12 / 2 + 2 * Origin_Width_Text_ / 28, + DialogOriginWidth_ * Size / 12 / 2 + 2 * TextOriginWidth_ / 28, NULL, - Origin_Width_Text_*Size / 12, - Origin_Height_Text_*Size / 12, + TextOriginWidth_*Size / 12, + TextOriginHeight_*Size / 12, SWP_NOACTIVATE | SWP_NOZORDER ); InvalidateRect(Handle_Dialog, NULL, TRUE); } VOID Dialog_Main::Topmost_Check() { - BOOL Top_State = GetWindowLong(Dialog_Main::Handle_Get(), GWL_EXSTYLE) & WS_EX_TOPMOST; + BOOL TopState = GetWindowLong(Dialog_Main::Handle_Get(), GWL_EXSTYLE) & WS_EX_TOPMOST; static BOOL First = TRUE; if (First == FALSE) { return; } - if (Top_State == FALSE) { + if (TopState == FALSE) { MessageBoxW(NULL, L"top error", L"top error", MB_OK); First = FALSE; } diff --git a/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.h b/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.h index d406e31..32a2358 100644 --- a/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.h +++ b/NetSpeed/NetSpeed/Dialog/Dialog_Main/Dialog_Main.h @@ -5,7 +5,7 @@ class Dialog_Main; class Dialog_Main :public Dialog { public: - static INT_PTR WINAPI Process(HWND Handle_Dialog, UINT Message_Dialog, WPARAM Param_WORD, LPARAM Param_LONG); + static INT_PTR WINAPI Process(HWND Handle_Dialog, UINT DialogMessage, WPARAM ParamWORD, LPARAM ParamLONG); public: static VOID ColorBackground_Set(COLORREF Background_Color); static VOID ColorText_Set(COLORREF Text_Color); @@ -17,14 +17,14 @@ class Dialog_Main :public Dialog { static VOID Topmost_Check(); static VOID Transparency_Set(INT Transparency); private: - static HBRUSH Bursh_Background_; - static HBRUSH Bursh_Text_; static COLORREF Color_Background_; static COLORREF Color_Text_; - static HFONT Font_Text_; - static LONG Origin_Height_Dialog_; - static LONG Origin_Height_Text_; - static LONG Origin_Width_Dialog_; - static LONG Origin_Width_Text_; - static HPEN Pen_Background_; + static LONG DialogOriginHeight_; + static LONG DialogOriginWidth_; + static HBRUSH Handle_Bursh_Background_; + static HBRUSH Handle_Bursh_Text_; + static HFONT Handle_Font_Text_; + static HPEN Handle_Pen_Background_; + static LONG TextOriginHeight_; + static LONG TextOriginWidth_; }; diff --git a/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.cpp b/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.cpp index 4f6260a..457dfc6 100644 --- a/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.cpp +++ b/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.cpp @@ -9,83 +9,70 @@ //public: -INT_PTR Dialog_Setting::Process(HWND Handle_Dialog, UINT Message_Dialog, WPARAM Param_WORD, LPARAM Param_LONG) { +INT_PTR Dialog_Setting::Process(HWND Handle_Dialog, UINT DialogMessage, WPARAM Param_WORD, LPARAM Param_LONG) { Handle_Set(Handle_Dialog); BOOL Result_Process = TRUE; - switch (Message_Dialog) { - case WM_CLOSE: - { + switch (DialogMessage) { + case WM_CLOSE: { DestroyWindow(Handle_Dialog); return 0; } - case WM_COMMAND: - { + case WM_COMMAND: { switch (LOWORD(Param_WORD)) { - case ID_Button_BackgroundColor: - { + case ID_Button_BackgroundColor: { COLORREF Color_Background = Registry::ColorBackground_Get(); - Color_Choose(&Color_Background); + SelectColor(&Color_Background); Registry::ColorBackground_Set(Color_Background); Dialog_Main::ColorBackground_Set(Color_Background); break; } - case ID_Button_Clean: - { + case ID_Button_Clean: { Registry::Clean(); break; } - case ID_Button_CleanAndExit: - { + case ID_Button_CleanAndExit: { Registry::Clean(); Dialog_Main::Destroy(); Dialog_Setting::Destroy(); break; } - case ID_Button_TextColor: - { + case ID_Button_TextColor: { COLORREF Color_Text = Registry::ColorText_Get(); - Dialog_Setting::Color_Choose(&Color_Text); + Dialog_Setting::SelectColor(&Color_Text); Registry::ColorText_Set(Color_Text); Dialog_Main::ColorText_Set(Color_Text); break; } - case ID_Combo_Language: - { + case ID_Combo_Language: { switch (HIWORD(Param_WORD)) { - case CBN_SELCHANGE: - { + case CBN_SELCHANGE: { HWND Handle_Combo_Language = GetDlgItem(Handle_Dialog, ID_Combo_Language); INT Languae_Index = ComboBox_GetCurSel(Handle_Combo_Language); Registry::Language_Set(Languae_Index); - Dialog_Setting::Gather_All(); + Dialog_Setting::GatherAll(); break; } - default: - { + default: { Result_Process = FALSE; } } break; } - case ID_Check_Show: - { + case ID_Check_Show: { HWND Handle_Check_Show = GetDlgItem(Handle_Dialog, ID_Check_Show); BOOL Show = Button_GetCheck(Handle_Check_Show); Dialog_Main::Show_Set(Show); break; } - case ID_Check_Startup: - { + case ID_Check_Startup: { HWND Handle_Check_Startup = GetDlgItem(Handle_Dialog, ID_Check_Startup); BOOL Startup = Button_GetCheck(Handle_Check_Startup); Registry::Startup_Set(Startup); break; } - case ID_Edit_Size: - { + case ID_Edit_Size: { switch (HIWORD(Param_WORD)) { - case EN_CHANGE: - { + case EN_CHANGE: { WCHAR Size_Text[4]; GetDlgItemTextW(Handle_Dialog, ID_Edit_Size, Size_Text, 4); INT Size = _wtoi(Size_Text); @@ -100,58 +87,49 @@ INT_PTR Dialog_Setting::Process(HWND Handle_Dialog, UINT Message_Dialog, WPARAM Dialog_Main::Size_Set(Size); break; } - default: - { + default: { Result_Process = FALSE; } } break; } - default: - { + default: { Result_Process = FALSE; } } break; } - case WM_HSCROLL: - { + case WM_HSCROLL: { HWND Handle_Slider_Transparency = GetDlgItem(Handle_Dialog, ID_Slider_Transparency); if (Param_LONG == (LPARAM)Handle_Slider_Transparency) { INT Position_Slider = HIWORD(Param_WORD); switch (LOWORD(Param_WORD)) { - case TB_THUMBTRACK: - { + case TB_THUMBTRACK: { Dialog_Main::Transparency_Set(Position_Slider); std::wstring Transparency_wstring = Dialog_Setting::Transparency_String(Position_Slider); SetDlgItemTextW(Handle_Dialog, ID_Static_Transparency, Transparency_wstring.c_str()); break; } - case TB_THUMBPOSITION: - { + case TB_THUMBPOSITION: { Registry::Transparency_Set(Position_Slider); break; } - default: - { + default: { Result_Process = FALSE; } } } break; } - case WM_INITDIALOG: - { - Dialog_Setting::Gather_All(); + case WM_INITDIALOG: { + Dialog_Setting::GatherAll(); break; } - case WM_NCDESTROY: - { + case WM_NCDESTROY: { Dialog_Setting::Handle_Set(NULL); return TRUE; } - default: - { + default: { Result_Process = FALSE; } } @@ -160,44 +138,28 @@ INT_PTR Dialog_Setting::Process(HWND Handle_Dialog, UINT Message_Dialog, WPARAM //public: -VOID Dialog_Setting::Color_Choose(COLORREF *Color_Bind) { - CHOOSECOLOR Color_Choose; +VOID Dialog_Setting::SelectColor(COLORREF *Color_Bind) { + CHOOSECOLOR ColorChooser; COLORREF Color_Custom[16]; - for (INT ColorCustom_Get_Index = 0; ColorCustom_Get_Index <= 15; ColorCustom_Get_Index++) { - Color_Custom[ColorCustom_Get_Index] = Registry::ColorCustom_Get(ColorCustom_Get_Index); + for (INT ColorCustomIndex = 0; ColorCustomIndex <= 15; ColorCustomIndex++) { + Color_Custom[ColorCustomIndex] = Registry::ColorCustom_Get(ColorCustomIndex); } - Color_Choose.lStructSize = sizeof(CHOOSECOLOR); - Color_Choose.hwndOwner = Dialog_Setting::Handle_Get(); - Color_Choose.hInstance = NULL; - Color_Choose.rgbResult = *Color_Bind; - Color_Choose.lpCustColors = Color_Custom; - Color_Choose.Flags = CC_FULLOPEN | CC_RGBINIT; - Color_Choose.lCustData = 0; - Color_Choose.lpfnHook = NULL; - Color_Choose.lpTemplateName = NULL; - ChooseColor(&Color_Choose); - *Color_Bind = Color_Choose.rgbResult; - for (INT ColorCustom_Set_Index = 0; ColorCustom_Set_Index <= 15; ColorCustom_Set_Index++) { - Registry::ColorCustom_Set(ColorCustom_Set_Index, Color_Custom[ColorCustom_Set_Index]); + ColorChooser.lStructSize = sizeof(CHOOSECOLOR); + ColorChooser.hwndOwner = Dialog_Setting::Handle_Get(); + ColorChooser.hInstance = NULL; + ColorChooser.rgbResult = *Color_Bind; + ColorChooser.lpCustColors = Color_Custom; + ColorChooser.Flags = CC_FULLOPEN | CC_RGBINIT; + ColorChooser.lCustData = 0; + ColorChooser.lpfnHook = NULL; + ColorChooser.lpTemplateName = NULL; + ChooseColor(&ColorChooser); + *Color_Bind = ColorChooser.rgbResult; + for (INT ColorCustomSetIndex = 0; ColorCustomSetIndex <= 15; ColorCustomSetIndex++) { + Registry::ColorCustom_Set(ColorCustomSetIndex, Color_Custom[ColorCustomSetIndex]); } } -VOID Dialog_Setting::Gather_All() { - Dialog_Setting::Gather_Button_Clean(); - Dialog_Setting::Gather_Button_CleanAndExit(); - Dialog_Setting::Gather_Button_ColorBackground(); - Dialog_Setting::Gather_Button_ColorText(); - Dialog_Setting::Gather_Caption(); - Dialog_Setting::Gather_Check_Show(); - Dialog_Setting::Gather_Check_Startup(); - Dialog_Setting::Gather_Combo_Language(); - Dialog_Setting::Gather_Edit_Size(); - Dialog_Setting::Gather_Slider_Transparency(); - Dialog_Setting::Gather_Static_Language(); - Dialog_Setting::Gather_Static_Size(); - Dialog_Setting::Gather_Static_Transparency(); -} - VOID Dialog_Setting::Gather_Button_Clean() { SetDlgItemTextW(Dialog_Setting::Handle_Get(), ID_Button_Clean, Text::Button_Clean().c_str()); } @@ -223,7 +185,7 @@ VOID Dialog_Setting::Gather_Check_Show() { HWND Handle_Dialog = Dialog_Setting::Handle_Get(); HWND Handle_Check_Show = GetDlgItem(Handle_Dialog, ID_Check_Show); Button_SetCheck(Handle_Check_Show, Show); - SetDlgItemTextW(Handle_Dialog, ID_Check_Show, Text::Menu_Item_Show().c_str()); + SetDlgItemTextW(Handle_Dialog, ID_Check_Show, Text::MenuItem_Show().c_str()); } VOID Dialog_Setting::Gather_Check_Startup() { @@ -231,7 +193,7 @@ VOID Dialog_Setting::Gather_Check_Startup() { HWND Handle_Dialog = Dialog_Setting::Handle_Get(); HWND Handle_Check_Startup = GetDlgItem(Handle_Dialog, ID_Check_Startup); Button_SetCheck(Handle_Check_Startup, Startup); - SetDlgItemTextW(Handle_Dialog, ID_Check_Startup, Text::Menu_Item_Startup().c_str()); + SetDlgItemTextW(Handle_Dialog, ID_Check_Startup, Text::MenuItem_Startup().c_str()); } VOID Dialog_Setting::Gather_Combo_Language() { @@ -268,6 +230,22 @@ VOID Dialog_Setting::Gather_Static_Transparency() { SetDlgItemTextW(Dialog_Setting::Handle_Get(), ID_Static_Transparency, Transparency_wstring.c_str()); } +VOID Dialog_Setting::GatherAll() { + Dialog_Setting::Gather_Button_Clean(); + Dialog_Setting::Gather_Button_CleanAndExit(); + Dialog_Setting::Gather_Button_ColorBackground(); + Dialog_Setting::Gather_Button_ColorText(); + Dialog_Setting::Gather_Caption(); + Dialog_Setting::Gather_Check_Show(); + Dialog_Setting::Gather_Check_Startup(); + Dialog_Setting::Gather_Combo_Language(); + Dialog_Setting::Gather_Edit_Size(); + Dialog_Setting::Gather_Slider_Transparency(); + Dialog_Setting::Gather_Static_Language(); + Dialog_Setting::Gather_Static_Size(); + Dialog_Setting::Gather_Static_Transparency(); +} + //private: std::wstring Dialog_Setting::Transparency_String(INT Transparency) { diff --git a/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.h b/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.h index a6b5326..cd0d8bf 100644 --- a/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.h +++ b/NetSpeed/NetSpeed/Dialog/Dialog_Setting/Dialog_Setting.h @@ -6,10 +6,9 @@ class Dialog_Setting; class Dialog_Setting :public Dialog { public: - static INT_PTR WINAPI Process(HWND Handle_Dialog, UINT Message_Dialog, WPARAM Param_WORD, LPARAM Param_LONG); - static VOID Color_Choose(COLORREF *Color_Bind); + static INT_PTR WINAPI Process(HWND Handle_Dialog, UINT DialogMessage, WPARAM ParamWORD, LPARAM ParamLONG); + static VOID SelectColor(COLORREF *Color_Bind); public: - static VOID Gather_All(); static VOID Gather_Button_Clean(); static VOID Gather_Button_CleanAndExit(); static VOID Gather_Button_ColorBackground(); @@ -23,6 +22,7 @@ class Dialog_Setting :public Dialog { static VOID Gather_Static_Language(); static VOID Gather_Static_Size(); static VOID Gather_Static_Transparency(); + static VOID GatherAll(); private: static std::wstring Transparency_String(INT Transparency); }; diff --git a/NetSpeed/NetSpeed/Main.cpp b/NetSpeed/NetSpeed/Main.cpp index 6571723..4392cb1 100644 --- a/NetSpeed/NetSpeed/Main.cpp +++ b/NetSpeed/NetSpeed/Main.cpp @@ -9,17 +9,17 @@ #include "Resource/resource.h" #include "Text/Text.h" -std::wstring File_Name; -std::wstring File_Path; +std::wstring FileName; +std::wstring FilePath; -INT WINAPI wWinMain(HINSTANCE Handle_Instance, HINSTANCE Handle_Instance_Previous, LPWSTR Commond, INT Show_Commend) { +INT WINAPI wWinMain(HINSTANCE Handle_Instance, HINSTANCE Handle_PreviousInstance, LPWSTR Commond, INT ShowCommend) { SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE); - WCHAR Path_File[MAX_PATH]; - GetModuleFileNameW(NULL, Path_File, MAX_PATH); - File_Path = Path_File; - File_Name = PathFindFileNameW(Path_File); - File_Name.erase(File_Name.end() - 4, File_Name.end()); + WCHAR PathFile[MAX_PATH]; + GetModuleFileNameW(NULL, PathFile, MAX_PATH); + FilePath = PathFile; + FileName = PathFindFileNameW(PathFile); + FileName.erase(FileName.end() - 4, FileName.end()); Text::Init(); Menu::Init(); diff --git a/NetSpeed/NetSpeed/Main.h b/NetSpeed/NetSpeed/Main.h index 9a43dec..ef174a0 100644 --- a/NetSpeed/NetSpeed/Main.h +++ b/NetSpeed/NetSpeed/Main.h @@ -2,5 +2,5 @@ #include #include -extern std::wstring File_Name; -extern std::wstring File_Path; +extern std::wstring FileName; +extern std::wstring FilePath; diff --git a/NetSpeed/NetSpeed/Menu/Menu.cpp b/NetSpeed/NetSpeed/Menu/Menu.cpp index 164e810..d407478 100644 --- a/NetSpeed/NetSpeed/Menu/Menu.cpp +++ b/NetSpeed/NetSpeed/Menu/Menu.cpp @@ -24,26 +24,23 @@ VOID Menu::Pop() { //Show BOOL Show = IsWindowVisible(Dialog_Main::Handle_Get()); if (Show == TRUE) { - ModifyMenu(Handle_, Item::Show, MF_BYPOSITION | MF_STRING, WM_MENU_SHOW, Text::Menu_Item_Hide().c_str()); + ModifyMenu(Handle_, Item::Show, MF_BYPOSITION | MF_STRING, WM_MENU_SHOW, Text::MenuItem_Hide().c_str()); } else if (Show == FALSE) { - ModifyMenu(Handle_, Item::Show, MF_BYPOSITION | MF_STRING, WM_MENU_SHOW, Text::Menu_Item_Show().c_str()); + ModifyMenu(Handle_, Item::Show, MF_BYPOSITION | MF_STRING, WM_MENU_SHOW, Text::MenuItem_Show().c_str()); } //Startup BOOL Startup = Registry::Startup_Get(); if (Startup == TRUE) { - ModifyMenuW(Handle_, Item::Startup, MF_BYPOSITION | MF_STRING | MF_CHECKED, WM_MENU_STARTUP, Text::Menu_Item_Startup().c_str()); + ModifyMenuW(Handle_, Item::Startup, MF_BYPOSITION | MF_STRING | MF_CHECKED, WM_MENU_STARTUP, Text::MenuItem_Startup().c_str()); } else if (Startup == FALSE) { - ModifyMenuW(Handle_, Item::Startup, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, WM_MENU_STARTUP, Text::Menu_Item_Startup().c_str()); - } - else { - MessageBoxW(NULL, Text::Message_AdapterFindFail().c_str(), NULL, MB_OK); + ModifyMenuW(Handle_, Item::Startup, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, WM_MENU_STARTUP, Text::MenuItem_Startup().c_str()); } //Setting - ModifyMenu(Handle_, Item::Setting, MF_BYPOSITION | MF_STRING, WM_MENU_SETTING, Text::Menu_Item_Setting().c_str()); + ModifyMenu(Handle_, Item::Setting, MF_BYPOSITION | MF_STRING, WM_MENU_SETTING, Text::MenuItem_Setting().c_str()); //Exit - ModifyMenu(Handle_, Item::Exit, MF_BYPOSITION | MF_STRING, WM_MENU_EXIT, Text::Menu_Item_Exit().c_str()); + ModifyMenu(Handle_, Item::Exit, MF_BYPOSITION | MF_STRING, WM_MENU_EXIT, Text::MenuItem_Exit().c_str()); SetForegroundWindow(Dialog_Main::Handle_Get()); POINT Point_Cursor; GetCursorPos(&Point_Cursor); diff --git a/NetSpeed/NetSpeed/NetSpeed.vcxproj b/NetSpeed/NetSpeed/NetSpeed.vcxproj index 44bd91f..2790ef0 100644 --- a/NetSpeed/NetSpeed/NetSpeed.vcxproj +++ b/NetSpeed/NetSpeed/NetSpeed.vcxproj @@ -51,7 +51,7 @@ 15.0 {3904678E-7C22-48DD-87A0-D938897C53BF} NetSpeed - 10.0.17134.0 + 10.0.17763.0 diff --git a/NetSpeed/NetSpeed/Registry/Registry.cpp b/NetSpeed/NetSpeed/Registry/Registry.cpp index a77e8ae..fa62189 100644 --- a/NetSpeed/NetSpeed/Registry/Registry.cpp +++ b/NetSpeed/NetSpeed/Registry/Registry.cpp @@ -37,17 +37,20 @@ const std::wstring Registry::Value_Transparency_ = L"Transparency"; //public: VOID Registry::Clean() { + std::wstring CleanFinishMessage = Text::Message_CleanFinish(); Registry::Startup_Set(FALSE); + Registry::Language_Set(0); + Dialog_Setting::GatherAll(); RegDeleteTreeW(HKEY_CURRENT_USER, Path_NetSpeed_.c_str()); - MessageBoxW(NULL, Text::Message_CleanFinish().c_str(), L"", MB_OK); + MessageBoxW(NULL, CleanFinishMessage.c_str(), L"", MB_OK); } //public: COLORREF Registry::ColorBackground_Get() { COLORREF ColorBackground; - LSTATUS Status_ColorBackground = Registry::Value_Get(Path_NetSpeed_, Value_ColorBackground_, RRF_RT_REG_DWORD, &ColorBackground); - if (Status_ColorBackground != ERROR_SUCCESS) { + LSTATUS ColorBackgroundStatus = Registry::Value_Get(Path_NetSpeed_, Value_ColorBackground_, RRF_RT_REG_DWORD, &ColorBackground); + if (ColorBackgroundStatus != ERROR_SUCCESS) { ColorBackground = RGB(0, 0, 0); Registry::ColorBackground_Set(ColorBackground); } @@ -58,25 +61,25 @@ VOID Registry::ColorBackground_Set(COLORREF ColorBackground) { Value_Set(Path_NetSpeed_, Value_ColorBackground_, REG_DWORD, (PBYTE)&ColorBackground, sizeof(COLORREF)); } -COLORREF Registry::ColorCustom_Get(INT ColorCustom_Index) { +COLORREF Registry::ColorCustom_Get(INT ColorCustomIndex) { COLORREF ColorCustom; - LSTATUS Status_ColorCustom = Registry::Value_Get(Path_NetSpeed_, Value_ColorCustom_[ColorCustom_Index], RRF_RT_REG_DWORD, &ColorCustom); - if (Status_ColorCustom != ERROR_SUCCESS) { + LSTATUS ColorCustomStatus = Registry::Value_Get(Path_NetSpeed_, Value_ColorCustom_[ColorCustomIndex], RRF_RT_REG_DWORD, &ColorCustom); + if (ColorCustomStatus != ERROR_SUCCESS) { ColorCustom = RGB(255, 255, 255); - Registry::ColorCustom_Set(ColorCustom_Index, ColorCustom); + Registry::ColorCustom_Set(ColorCustomIndex, ColorCustom); } return ColorCustom; } -VOID Registry::ColorCustom_Set(INT ColorCustom_Index, COLORREF ColorCustom) { - Registry::Value_Set(Path_NetSpeed_, Value_ColorCustom_[ColorCustom_Index], REG_DWORD, (PBYTE)&ColorCustom, sizeof(COLORREF)); +VOID Registry::ColorCustom_Set(INT ColorCustomIndex, COLORREF ColorCustom) { + Registry::Value_Set(Path_NetSpeed_, Value_ColorCustom_[ColorCustomIndex], REG_DWORD, (PBYTE)&ColorCustom, sizeof(COLORREF)); } COLORREF Registry::ColorText_Get() { COLORREF ColorText; - LSTATUS Status_ColorText = Registry::Value_Get(Path_NetSpeed_, Value_ColorText_, RRF_RT_REG_DWORD, &ColorText); - if (Status_ColorText != ERROR_SUCCESS) { + LSTATUS ColorTextStatus = Registry::Value_Get(Path_NetSpeed_, Value_ColorText_, RRF_RT_REG_DWORD, &ColorText); + if (ColorTextStatus != ERROR_SUCCESS) { ColorText = RGB(255, 255, 255); Registry::ColorText_Set(ColorText); } @@ -89,21 +92,21 @@ VOID Registry::ColorText_Set(COLORREF ColorText) { INT Registry::Language_Get() { WCHAR Language[100]; - LSTATUS Status_Language = Registry::Value_Get(Path_NetSpeed_, Value_Language_, RRF_RT_REG_SZ, Language); - if (Status_Language == ERROR_SUCCESS) { + LSTATUS LanguageStatus = Registry::Value_Get(Path_NetSpeed_, Value_Language_, RRF_RT_REG_SZ, Language); + if (LanguageStatus == ERROR_SUCCESS) { INT Language_Exist = Text::Language_Get(Language); if (Language_Exist != -1) { return Language_Exist; } } - std::wstring Language_Name = Text::Name(0); - Registry::Value_Set(Path_NetSpeed_, Value_Language_.c_str(), REG_SZ, (PBYTE)Language_Name.c_str(), Language_Name.length() * sizeof(WCHAR)); + std::wstring LanguageName = Text::Name(0); + Registry::Value_Set(Path_NetSpeed_, Value_Language_.c_str(), REG_SZ, (PBYTE)LanguageName.c_str(), LanguageName.length() * sizeof(WCHAR)); return 0; } -VOID Registry::Language_Set(INT Language_Index) { - std::wstring Language_Name = Text::Name(Language_Index); - Registry::Value_Set(Path_NetSpeed_, Value_Language_.c_str(), REG_SZ, (PBYTE)Language_Name.c_str(), Language_Name.length() * sizeof(WCHAR)); +VOID Registry::Language_Set(INT LanguageIndex) { + std::wstring LanguageName = Text::Name(LanguageIndex); + Registry::Value_Set(Path_NetSpeed_, Value_Language_.c_str(), REG_SZ, (PBYTE)LanguageName.c_str(), LanguageName.length() * sizeof(WCHAR)); } std::set Registry::PCI_Get() { @@ -120,12 +123,12 @@ std::set Registry::PCI_Get() { &Key_Network, NULL ); - INT Index_Path = 0; - WCHAR Path_Name[MAX_PATH]; + INT PathIndex = 0; + WCHAR PathName[MAX_PATH]; DWORD Name_Size = MAX_PATH; - while (RegEnumKeyExW(Key_Network, Index_Path, Path_Name, &Name_Size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { - if (Path_Name[0] == L'{') { - std::wstring Path_New = Path_Network_ + L"\\" + Path_Name + L"\\Connection"; + while (RegEnumKeyExW(Key_Network, PathIndex, PathName, &Name_Size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) { + if (PathName[0] == L'{') { + std::wstring Path_New = Path_Network_ + L"\\" + PathName + L"\\Connection"; WCHAR Value[MAX_PATH]; DWORD Value_Size = MAX_PATH; RegGetValueW( @@ -138,24 +141,22 @@ std::set Registry::PCI_Get() { &Value_Size ); if (std::wstring(Value).find(L"PCI") == 0) { - Set_PCI.insert(Path_Name); + Set_PCI.insert(PathName); } } - Index_Path++; + PathIndex++; Name_Size = MAX_PATH; } RegCloseKey(Key_Network); return Set_PCI; - - } POINT Registry::Position_Get() { POINT Poisition; - LSTATUS Status_PositionX = Registry::Value_Get(Path_NetSpeed_, Value_PositionX_, RRF_RT_REG_DWORD, &Poisition.x); - LSTATUS Status_PositionY = Registry::Value_Get(Path_NetSpeed_, Value_PositionY_, RRF_RT_REG_DWORD, &Poisition.y); - if (Status_PositionX != ERROR_SUCCESS || Status_PositionY != ERROR_SUCCESS) { + LSTATUS PositionXStatus = Registry::Value_Get(Path_NetSpeed_, Value_PositionX_, RRF_RT_REG_DWORD, &Poisition.x); + LSTATUS PositionYStatus = Registry::Value_Get(Path_NetSpeed_, Value_PositionY_, RRF_RT_REG_DWORD, &Poisition.y); + if (PositionXStatus != ERROR_SUCCESS || PositionYStatus != ERROR_SUCCESS) { Poisition = Dialog_Main::Position_Get(); Registry::Position_Set(Poisition); } @@ -169,8 +170,8 @@ VOID Registry::Position_Set(POINT Position) { INT Registry::Size_Get() { INT Size; - LSTATUS Status_Size = Registry::Value_Get(Path_NetSpeed_, Value_Size_, RRF_RT_REG_DWORD, &Size); - if (Status_Size != ERROR_SUCCESS) { + LSTATUS SizeStatus = Registry::Value_Get(Path_NetSpeed_, Value_Size_, RRF_RT_REG_DWORD, &Size); + if (SizeStatus != ERROR_SUCCESS) { Size = 12; Registry::Size_Set(Size); } @@ -182,21 +183,21 @@ VOID Registry::Size_Set(INT Size) { } BOOL Registry::Startup_Get() { - LSTATUS Status_Registry_Startup = Registry::Value_Get(Path_Startup_, File_Name, RRF_RT_REG_SZ, NULL); - if (Status_Registry_Startup != ERROR_SUCCESS) { + LSTATUS StartupStatus = Registry::Value_Get(Path_Startup_, FileName, RRF_RT_REG_SZ, NULL); + if (StartupStatus != ERROR_SUCCESS) { return FALSE; } //Rest the .exe path - Registry::Value_Set(Path_Startup_, File_Name, REG_SZ, (PBYTE)File_Path.c_str(), File_Path.length() * sizeof(WCHAR)); + Registry::Value_Set(Path_Startup_, FileName, REG_SZ, (PBYTE)FilePath.c_str(), FilePath.length() * sizeof(WCHAR)); return TRUE; } VOID Registry::Startup_Set(BOOL Startup) { if (Startup == TRUE) { - Registry::Value_Set(Path_Startup_, File_Name, REG_SZ, (PBYTE)File_Path.c_str(), File_Path.length() * sizeof(WCHAR)); + Registry::Value_Set(Path_Startup_, FileName, REG_SZ, (PBYTE)FilePath.c_str(), FilePath.length() * sizeof(WCHAR)); } else { - RegDeleteKeyValueW(HKEY_CURRENT_USER, Path_Startup_.c_str(), File_Name.c_str()); + RegDeleteKeyValueW(HKEY_CURRENT_USER, Path_Startup_.c_str(), FileName.c_str()); } if (Dialog_Setting::Handle_Get() != NULL) { Dialog_Setting::Gather_Check_Startup(); @@ -205,8 +206,8 @@ VOID Registry::Startup_Set(BOOL Startup) { INT Registry::Transparency_Get() { INT Transparency; - LSTATUS Status_Transparency = Registry::Value_Get(Path_NetSpeed_, Value_Transparency_, RRF_RT_REG_DWORD, &Transparency); - if (Status_Transparency != ERROR_SUCCESS) { + LSTATUS TransparencyStatus = Registry::Value_Get(Path_NetSpeed_, Value_Transparency_, RRF_RT_REG_DWORD, &Transparency); + if (TransparencyStatus != ERROR_SUCCESS) { Transparency = 65; Registry::Transparency_Set(Transparency); } diff --git a/NetSpeed/NetSpeed/Registry/Registry.h b/NetSpeed/NetSpeed/Registry/Registry.h index 0bbc624..0074b16 100644 --- a/NetSpeed/NetSpeed/Registry/Registry.h +++ b/NetSpeed/NetSpeed/Registry/Registry.h @@ -12,12 +12,12 @@ class Registry { public: static COLORREF ColorBackground_Get(); static VOID ColorBackground_Set(COLORREF ColorBackground); - static COLORREF ColorCustom_Get(INT ColorCustom_Index); - static VOID ColorCustom_Set(INT ColorCustom_Index, COLORREF ColorCustom); + static COLORREF ColorCustom_Get(INT ColorCustomIndex); + static VOID ColorCustom_Set(INT ColorCustomIndex, COLORREF ColorCustom); static COLORREF ColorText_Get(); static VOID ColorText_Set(COLORREF ColorText); static INT Language_Get(); - static VOID Language_Set(INT Language_Index); + static VOID Language_Set(INT LanguageIndex); static std::set PCI_Get(); static POINT Position_Get(); static VOID Position_Set(POINT Position); diff --git a/NetSpeed/NetSpeed/Resource/NetSpeed.rc b/NetSpeed/NetSpeed/Resource/NetSpeed.rc index 4fbcedddf5beca276879063ee332af4e0acbf921..038c747461fc9f84fa8779c932a75e44691565d1 100644 GIT binary patch delta 42 vcmccScg=4@oiwA#B-X+gf>r8IKTz~Q_l|} delta 42 vcmccScg=4@oiwA-B-X+gf>r8IKTz~Qw Text::Vector_Text_(Text::Language::Total); +std::vector Text::TextVector_(Text::Language::Total); //public: VOID Text::Init() { - Vector_Text_[Language::Chinese_Simplified].Button_Clean_ = L"清理"; - Vector_Text_[Language::Chinese_Simplified].Button_CleanAndExit_ = L"清理并退出"; - Vector_Text_[Language::Chinese_Simplified].Button_ColorBackground_ = L"背景颜色"; - Vector_Text_[Language::Chinese_Simplified].Button_ColorText_ = L"文字颜色"; - Vector_Text_[Language::Chinese_Simplified].Dialog_Setting_Caption_ = L"设置"; - Vector_Text_[Language::Chinese_Simplified].Menu_Item_Clean_ = L"清理注册表"; - Vector_Text_[Language::Chinese_Simplified].Menu_Item_Exit_ = L"退出"; - Vector_Text_[Language::Chinese_Simplified].Menu_Item_Hide_ = L"隐藏"; - Vector_Text_[Language::Chinese_Simplified].Menu_Item_Setting_ = L"设置"; - Vector_Text_[Language::Chinese_Simplified].Menu_Item_Show_ = L"显示"; - Vector_Text_[Language::Chinese_Simplified].Menu_Item_Startup_ = L"开机自启"; - Vector_Text_[Language::Chinese_Simplified].Message_AdapterFindFail_ = L"查找网卡失败。"; - Vector_Text_[Language::Chinese_Simplified].Message_RegistryOpenFail_ = L"打开注册表失败。"; - Vector_Text_[Language::Chinese_Simplified].Name_ = L"简体中文"; - Vector_Text_[Language::Chinese_Simplified].Static_Language_ = L"语言"; - Vector_Text_[Language::Chinese_Simplified].Static_Size_ = L"大小"; - Vector_Text_[Language::Chinese_Simplified].Static_Transparency_ = L"透明度:"; + Text &Text_ChineseSimplified = TextVector_[Language::ChineseSimplified]; + Text_ChineseSimplified.Button_Clean_ = L"清理"; + Text_ChineseSimplified.Button_CleanAndExit_ = L"清理并退出"; + Text_ChineseSimplified.Button_ColorBackground_ = L"背景颜色"; + Text_ChineseSimplified.Button_ColorText_ = L"文字颜色"; + Text_ChineseSimplified.Dialog_Setting_Caption_ = L"设置"; + Text_ChineseSimplified.MenuItem_Clean_ = L"清理注册表"; + Text_ChineseSimplified.MenuItem_Exit_ = L"退出"; + Text_ChineseSimplified.MenuItem_Hide_ = L"隐藏"; + Text_ChineseSimplified.MenuItem_Setting_ = L"设置"; + Text_ChineseSimplified.MenuItem_Show_ = L"显示"; + Text_ChineseSimplified.MenuItem_Startup_ = L"开机自启"; + Text_ChineseSimplified.Message_CreateSharedMemoryFail_ = L"创建共享内存失败。"; + Text_ChineseSimplified.Message_RegistryOpenFail_ = L"打开注册表失败。"; + Text_ChineseSimplified.Message_CleanFinish_ = L"清理注册表完成。"; + Text_ChineseSimplified.Name_ = L"简体中文"; + Text_ChineseSimplified.Static_Language_ = L"语言"; + Text_ChineseSimplified.Static_Size_ = L"大小"; + Text_ChineseSimplified.Static_Transparency_ = L"透明度:"; } INT Text::Language_Get(std::wstring Language_Name) { @@ -38,107 +40,107 @@ INT Text::Language_Get(std::wstring Language_Name) { } std::wstring Text::Name(INT Language) { - return Vector_Text_[Language].Name_; + return TextVector_[Language].Name_; } //public: std::wstring Text::Button_Clean() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Button_Clean_; + return TextVector_[Language_Index].Button_Clean_; } std::wstring Text::Button_CleanAndExit() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Button_CleanAndExit_; + return TextVector_[Language_Index].Button_CleanAndExit_; } std::wstring Text::Button_ColorBackground() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Button_ColorBackground_; + return TextVector_[Language_Index].Button_ColorBackground_; } std::wstring Text::Button_ColorText() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Button_ColorText_; + return TextVector_[Language_Index].Button_ColorText_; } std::wstring Text::Check_Show() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Check_Show_; + return TextVector_[Language_Index].Check_Show_; } std::wstring Text::Check_Startup() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Check_Startup_; + return TextVector_[Language_Index].Check_Startup_; } std::wstring Text::Dialog_Caption() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Dialog_Setting_Caption_; + return TextVector_[Language_Index].Dialog_Setting_Caption_; } -std::wstring Text::Menu_Item_Clean() { +std::wstring Text::MenuItem_Clean() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Menu_Item_Clean_; + return TextVector_[Language_Index].MenuItem_Clean_; } -std::wstring Text::Menu_Item_Exit() { +std::wstring Text::MenuItem_Exit() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Menu_Item_Exit_; + return TextVector_[Language_Index].MenuItem_Exit_; } -std::wstring Text::Menu_Item_Hide() { +std::wstring Text::MenuItem_Hide() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Menu_Item_Hide_; + return TextVector_[Language_Index].MenuItem_Hide_; } -std::wstring Text::Menu_Item_Setting() { +std::wstring Text::MenuItem_Setting() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Menu_Item_Setting_; + return TextVector_[Language_Index].MenuItem_Setting_; } -std::wstring Text::Menu_Item_Show() { +std::wstring Text::MenuItem_Show() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Menu_Item_Show_; + return TextVector_[Language_Index].MenuItem_Show_; } -std::wstring Text::Menu_Item_Startup() { +std::wstring Text::MenuItem_Startup() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Menu_Item_Startup_; + return TextVector_[Language_Index].MenuItem_Startup_; } -std::wstring Text::Message_AdapterFindFail() { +std::wstring Text::Message_CreateSharedMemoryFail() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Message_AdapterFindFail_; + return TextVector_[Language_Index].Message_CreateSharedMemoryFail_; } std::wstring Text::Message_RegistryOpenFail() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Message_RegistryOpenFail_; + return TextVector_[Language_Index].Message_RegistryOpenFail_; } std::wstring Text::Message_CleanFinish() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Message_CleanFinish_; + return TextVector_[Language_Index].Message_CleanFinish_; } std::wstring Text::Name() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Name_; + return TextVector_[Language_Index].Name_; } std::wstring Text::Static_Language() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Static_Language_; + return TextVector_[Language_Index].Static_Language_; } std::wstring Text::Static_Size() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Static_Size_; + return TextVector_[Language_Index].Static_Size_; } std::wstring Text::Static_Transparency() { INT Language_Index = Registry::Language_Get(); - return Vector_Text_[Language_Index].Static_Transparency_; + return TextVector_[Language_Index].Static_Transparency_; } diff --git a/NetSpeed/NetSpeed/Text/Text.h b/NetSpeed/NetSpeed/Text/Text.h index 2dc1f60..b34f621 100644 --- a/NetSpeed/NetSpeed/Text/Text.h +++ b/NetSpeed/NetSpeed/Text/Text.h @@ -1,5 +1,6 @@ #pragma once #include +#include #include class Text; @@ -7,11 +8,11 @@ class Text { public: enum Language { English, - Chinese_Simplified, + ChineseSimplified, Total }; static VOID Init(); - static INT Language_Get(std::wstring Language_Name); + static INT Language_Get(std::wstring LanguageName); static std::wstring Name(INT Language); public: static std::wstring Button_Clean(); @@ -21,39 +22,40 @@ class Text { static std::wstring Check_Show(); static std::wstring Check_Startup(); static std::wstring Dialog_Caption(); - static std::wstring Menu_Item_Clean(); - static std::wstring Menu_Item_Exit(); - static std::wstring Menu_Item_Hide(); - static std::wstring Menu_Item_Setting(); - static std::wstring Menu_Item_Show(); - static std::wstring Menu_Item_Startup(); + static std::wstring MenuItem_Clean(); + static std::wstring MenuItem_Exit(); + static std::wstring MenuItem_Hide(); + static std::wstring MenuItem_Setting(); + static std::wstring MenuItem_Show(); + static std::wstring MenuItem_Startup(); static std::wstring Message_CleanFinish(); - static std::wstring Message_AdapterFindFail(); + static std::wstring Message_CreateSharedMemoryFail(); static std::wstring Message_RegistryOpenFail(); static std::wstring Name(); static std::wstring Static_Language(); static std::wstring Static_Size(); static std::wstring Static_Transparency(); private: - static std::vector Vector_Text_; - std::wstring Menu_Item_Clean_ = L"Clean"; - std::wstring Menu_Item_Exit_ = L"Exit"; - std::wstring Menu_Item_Hide_ = L"Hide"; - std::wstring Menu_Item_Setting_ = L"Setting"; - std::wstring Menu_Item_Show_ = L"Show"; - std::wstring Menu_Item_Startup_ = L"Startup"; - std::wstring Message_AdapterFindFail_ = L"Can't find adapter."; - std::wstring Message_RegistryOpenFail_ = L"Can't open registry."; - std::wstring Message_CleanFinish_ = L"All registry has been cleanned."; - std::wstring Name_ = L"English"; + static std::vector TextVector_; +private: std::wstring Button_Clean_ = L"Clean"; std::wstring Button_CleanAndExit_ = L"Clean And Exit"; std::wstring Button_ColorBackground_ = L"Background Color"; std::wstring Button_ColorText_ = L"Text Color"; + std::wstring Check_Show_ = L"Show"; + std::wstring Check_Startup_ = L"Startup"; std::wstring Dialog_Setting_Caption_ = L"Setting"; + std::wstring MenuItem_Clean_ = L"Clean"; + std::wstring MenuItem_Exit_ = L"Exit"; + std::wstring MenuItem_Hide_ = L"Hide"; + std::wstring MenuItem_Setting_ = L"Setting"; + std::wstring MenuItem_Show_ = L"Show"; + std::wstring MenuItem_Startup_ = L"Startup"; + std::wstring Message_CreateSharedMemoryFail_ = L"Can't create shared memory."; + std::wstring Message_RegistryOpenFail_ = L"Can't open registry."; + std::wstring Message_CleanFinish_ = L"All registry has been cleanned."; + std::wstring Name_ = L"English"; std::wstring Static_Language_ = L"Language"; std::wstring Static_Transparency_ = L"Transparency:"; std::wstring Static_Size_ = L"Size"; - std::wstring Check_Show_ = L"Show"; - std::wstring Check_Startup_ = L"Startup"; }; diff --git a/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.cpp b/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.cpp index de67834..ed04db1 100644 --- a/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.cpp +++ b/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.cpp @@ -1,4 +1,5 @@ #include "Timer_Refresh.h" +#include #include #include "../Dialog/Dialog_Main/Dialog_Main.h" @@ -6,60 +7,30 @@ #include "../Resource/resource.h" #include "../Text/Text.h" -DWORD Timer_Refresh::Download_New_; -DWORD Timer_Refresh::Download_Old_; -BOOL Timer_Refresh::First_; +DWORD Timer_Refresh::DownloadOld_ = 0; +BOOL Timer_Refresh::First_ = TRUE; HANDLE Timer_Refresh::Handle_ = NULL; -std::set Timer_Refresh::Set_Adapter_; -std::set Timer_Refresh::Set_PCI_; -DWORD Timer_Refresh::Upload_New_; -DWORD Timer_Refresh::Upload_Old_; +HANDLE Timer_Refresh::Handle_SharedMap_ = NULL; +const SIZE_T Timer_Refresh::SharedMapSize_ = 0x1000; +LPWSTR Timer_Refresh::SharedMapView_ = NULL; +DWORD Timer_Refresh::UploadOld_ = 0; //public: VOID Timer_Refresh::Init() { - Set_PCI_ = Registry::PCI_Get(); - Set_Adapter_.clear(); - - DWORD Size_Table = sizeof(MIB_IFTABLE); - MIB_IFTABLE *Table_Adapter = (MIB_IFTABLE *)HeapAlloc(GetProcessHeap(), 0, Size_Table); - GetIfTable(Table_Adapter, &Size_Table, FALSE); - HeapFree(GetProcessHeap(), 0, Table_Adapter); - Table_Adapter = (MIB_IFTABLE *)HeapAlloc(GetProcessHeap(), 0, Size_Table); - GetIfTable(Table_Adapter, &Size_Table, FALSE); - DWORD Adapter_Number = Table_Adapter->dwNumEntries; - HeapFree(GetProcessHeap(), 0, Table_Adapter); - - static PMIB_IFROW Adapter_Info = (PMIB_IFROW)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IFROW)); - Adapter_Info->dwIndex = 0; - - for (DWORD Index_Adapter = 0; Index_Adapter <= Adapter_Number - 1; Index_Adapter++) { - Adapter_Info->dwIndex = Index_Adapter; - if (GetIfEntry(Adapter_Info) != NO_ERROR) { - continue; - } - for (std::wstring PCI : Set_PCI_) { - if (std::wstring(Adapter_Info->wszName).find(PCI) != std::wstring::npos) { - Set_Adapter_.insert(Adapter_Info->dwIndex); - } - } + Handle_SharedMap_ = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, SharedMapSize_, L"NetSpeed"); + if (Handle_SharedMap_ == NULL) { + MessageBoxW(NULL, Text::Message_CreateSharedMemoryFail().c_str(), L"", MB_OK); } - - HeapFree(GetProcessHeap(), 0, Adapter_Info); - if (Set_Adapter_.empty()) { - MessageBoxW(NULL, Text::Message_AdapterFindFail().c_str(), L"", MB_OK); - EndDialog(Dialog_Main::Handle_Get(), 0); + else { + SharedMapView_ = (LPWSTR)MapViewOfFile(Handle_SharedMap_, FILE_MAP_WRITE, 0, 0, 0); + if (SharedMapView_ == NULL) { + MessageBoxW(NULL, Text::Message_CreateSharedMemoryFail().c_str(), L"", MB_OK); + } } - - First_ = TRUE; - Download_Old_ = 0; - Upload_Old_ = 0; } VOID Timer_Refresh::Start() { - if (Set_Adapter_.empty()) { - return; - } CreateTimerQueueTimer(&Handle_, NULL, Timer_Refresh::Process, NULL, 0, 1000, 0); } @@ -67,41 +38,60 @@ VOID Timer_Refresh::Start() { VOID WINAPI Timer_Refresh::Process(PVOID Parameter, BOOLEAN) { Dialog_Main::Topmost_Check(); - PMIB_IFROW Adapter_Info_ = (PMIB_IFROW)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IFROW)); - for (DWORD Index_Adapter : Set_Adapter_) { - Adapter_Info_->dwIndex = Index_Adapter; - if (GetIfEntry(Adapter_Info_) != NO_ERROR) { - HeapFree(GetProcessHeap(), 0, Adapter_Info_); - Timer_Refresh::Init(); - return; + std::set PCISet = Registry::PCI_Get(); + DWORD TableSize = sizeof(MIB_IFTABLE); + PMIB_IFTABLE AdapterTable = (PMIB_IFTABLE)HeapAlloc(GetProcessHeap(), 0, TableSize); + GetIfTable(AdapterTable, &TableSize, FALSE); + HeapFree(GetProcessHeap(), 0, AdapterTable); + AdapterTable = (PMIB_IFTABLE)HeapAlloc(GetProcessHeap(), 0, TableSize); + GetIfTable(AdapterTable, &TableSize, FALSE); + DWORD AdapterNumber = AdapterTable->dwNumEntries; + HeapFree(GetProcessHeap(), 0, AdapterTable); + + PMIB_IFROW AdapterInfo = (PMIB_IFROW)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IFROW)); + AdapterInfo->dwIndex = 0; + + DWORD DownloadNew_ = 0; + DWORD UploadNew_ = 0; + for (DWORD AdapterIndex = 0; AdapterIndex <= AdapterNumber - 1; AdapterIndex++) { + AdapterInfo->dwIndex = AdapterIndex; + if (GetIfEntry(AdapterInfo) != NO_ERROR) { + continue; + } + for (std::wstring PCI : PCISet) { + if (std::wstring(AdapterInfo->wszName).find(PCI) != -1) { + DownloadNew_ += AdapterInfo->dwInOctets; + UploadNew_ += AdapterInfo->dwOutOctets; + } } - Download_New_ = Adapter_Info_->dwInOctets; - Upload_New_ = Adapter_Info_->dwOutOctets; } - HeapFree(GetProcessHeap(), 0, Adapter_Info_); - DOUBLE Download_Disparity = (Download_New_ - Download_Old_) / 1024.0; - DOUBLE Upload_Disparity = (Upload_New_ - Upload_Old_) / 1024.0; - std::wstring Unit_Download = L"K"; - std::wstring Unit_Upload = L"K"; - if (Download_Disparity > 1024) { - Download_Disparity = Download_Disparity / 1024.0; - Unit_Download = L"M"; + HeapFree(GetProcessHeap(), 0, AdapterInfo); + + CONST DWORD DownloadDisparityRaw = DownloadNew_ - DownloadOld_; + CONST DWORD UploadDisparityRaw = UploadNew_ - UploadOld_; + DOUBLE DownloadDisparity = DownloadDisparityRaw / 1024.0; + DOUBLE UploadDisparity = UploadDisparityRaw / 1024.0; + std::wstring UnitDownload = L"K"; + std::wstring UnitUpload = L"K"; + if (DownloadDisparity > 1024) { + DownloadDisparity = DownloadDisparity / 1024.0; + UnitDownload = L"M"; } - if (Upload_Disparity > 1024) { - Upload_Disparity = Upload_Disparity / 1024.0; - Unit_Upload = L"M"; + if (UploadDisparity > 1024) { + UploadDisparity = UploadDisparity / 1024.0; + UnitUpload = L"M"; } - std::wstring Download_Speed = std::to_wstring(Download_Disparity + 0.05); - std::wstring Upload_Speed = std::to_wstring(Upload_Disparity + 0.05); - Download_Speed.erase(Download_Speed.end() - 5, Download_Speed.end()); - Upload_Speed.erase(Upload_Speed.end() - 5, Upload_Speed.end()); - Download_Speed.append(Unit_Download); - Upload_Speed.append(Unit_Upload); - Download_Old_ = Download_New_; - Upload_Old_ = Upload_New_; + std::wstring DownloadSpeed = std::to_wstring(DownloadDisparity + 0.05); + std::wstring UploadSpeed = std::to_wstring(UploadDisparity + 0.05); + DownloadSpeed.erase(DownloadSpeed.end() - 5, DownloadSpeed.end()); + UploadSpeed.erase(UploadSpeed.end() - 5, UploadSpeed.end()); + DownloadSpeed.append(UnitDownload); + UploadSpeed.append(UnitUpload); + DownloadOld_ = DownloadNew_; + UploadOld_ = UploadNew_; HWND Handle_DialogMain = Dialog_Main::Handle_Get(); if (First_ == TRUE) { SetDlgItemTextW(Handle_DialogMain, ID_Static_Download, L"..."); @@ -109,6 +99,13 @@ VOID WINAPI Timer_Refresh::Process(PVOID Parameter, BOOLEAN) { First_ = FALSE; return; } - SetDlgItemTextW(Handle_DialogMain, ID_Static_Download, Download_Speed.c_str()); - SetDlgItemTextW(Handle_DialogMain, ID_Static_Upload, Upload_Speed.c_str()); + SetDlgItemTextW(Handle_DialogMain, ID_Static_Download, DownloadSpeed.c_str()); + SetDlgItemTextW(Handle_DialogMain, ID_Static_Upload, UploadSpeed.c_str()); + std::wstring SharedMapJson = + L"{\"download\":" + + std::to_wstring(DownloadDisparityRaw) + + L",\"upload\":" + + std::to_wstring(UploadDisparityRaw) + + L"}"; + StringCchCopyW(SharedMapView_, SharedMapSize_, SharedMapJson.c_str()); } diff --git a/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.h b/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.h index c50e1b1..e47f114 100644 --- a/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.h +++ b/NetSpeed/NetSpeed/Timer_Refresh/Timer_Refresh.h @@ -12,13 +12,12 @@ class Timer_Refresh { static VOID Init(); static VOID Start(); private: - static VOID WINAPI Process(PVOID lpParameter, BOOLEAN); - static DWORD Download_New_; - static DWORD Download_Old_; + static VOID WINAPI Process(PVOID Parameter, BOOLEAN); + static DWORD DownloadOld_; static BOOL First_; static HANDLE Handle_; - static std::set Set_Adapter_; - static std::set Set_PCI_; - static DWORD Upload_New_; - static DWORD Upload_Old_; + static HANDLE Handle_SharedMap_; + static const SIZE_T SharedMapSize_; + static LPWSTR SharedMapView_; + static DWORD UploadOld_; };