diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 05b9bb49b..4ea61bd52 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -435,9 +435,10 @@ LRESULT Notepad_plus::init(HWND hwnd) _dockingManager.init(_pPublicInterface->getHinst(), hwnd, &_pMainWindow); - if (nppGUI._isMinimizedToTray && _pTrayIco == NULL) + if (nppGUI._isMinimizedToTray && _pTrayIco == nullptr) { - HICON icon = ::LoadIcon(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_M30ICON)); + HICON icon = nullptr; + Notepad_plus_Window::loadTrayIcon(_pPublicInterface->getHinst(), &icon); _pTrayIco = new trayIconControler(hwnd, IDI_M30ICON, NPPM_INTERNAL_MINIMIZED_TRAY, icon, TEXT("")); } diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index 274494bbb..eb0615f1c 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -188,7 +188,9 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin } else { - _notepad_plus_plus_core._pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, NPPM_INTERNAL_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); + HICON icon = nullptr; + loadTrayIcon(_hInst, &icon); + _notepad_plus_plus_core._pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, NPPM_INTERNAL_MINIMIZED_TRAY, icon, TEXT("")); _notepad_plus_plus_core._pTrayIco->doTrayIcon(ADD); } diff --git a/PowerEditor/src/Notepad_plus_Window.h b/PowerEditor/src/Notepad_plus_Window.h index c1eb5ed18..84176a362 100644 --- a/PowerEditor/src/Notepad_plus_Window.h +++ b/PowerEditor/src/Notepad_plus_Window.h @@ -100,6 +100,19 @@ public: void setStartupBgColor(COLORREF BgColor); + static void loadIcon(HINSTANCE hinst, wchar_t* pszName, int cx, int cy, HICON* icon) + { + if (::LoadIconWithScaleDown(hinst, pszName, cx, cy, icon) != S_OK) + { + *icon = static_cast(::LoadImage(hinst, pszName, IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR)); + } + } + + static void loadTrayIcon(HINSTANCE hinst, HICON* icon) + { + loadIcon(hinst, MAKEINTRESOURCE(IDI_M30ICON), ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), icon); + } + private: Notepad_plus _notepad_plus_plus_core; static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index d45bb1d1b..178d51794 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1357,8 +1357,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_GETNPPVERSION: { const TCHAR* verStr = VERSION_VALUE; - TCHAR mainVerStr[16]; - TCHAR auxVerStr[16]; + TCHAR mainVerStr[16]{}; + TCHAR auxVerStr[16]{}; bool isDot = false; int j = 0; int k = 0; @@ -2537,7 +2537,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa if ((nppgui._isMinimizedToTray || _pPublicInterface->isPrelaunch()) && (wParam == SC_MINIMIZE)) { if (nullptr == _pTrayIco) - _pTrayIco = new trayIconControler(hwnd, IDI_M30ICON, NPPM_INTERNAL_MINIMIZED_TRAY, ::LoadIcon(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); + { + HICON icon = nullptr; + Notepad_plus_Window::loadTrayIcon(_pPublicInterface->getHinst(), &icon); + _pTrayIco = new trayIconControler(hwnd, IDI_M30ICON, NPPM_INTERNAL_MINIMIZED_TRAY, icon, TEXT("")); + } _pTrayIco->doTrayIcon(ADD); _dockingManager.showFloatingContainers(false);