From 50e95d22675b86b6afeacb6fdc217a0011f9528e Mon Sep 17 00:00:00 2001 From: ozone10 Date: Wed, 28 Dec 2022 16:47:43 +0100 Subject: [PATCH] Code enhancement: Replace undocumented functions Fix #12721, close #12722 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 4 +- PowerEditor/src/NppBigSwitch.cpp | 5 ++- PowerEditor/src/Parameters.cpp | 37 +++++-------------- PowerEditor/src/Parameters.h | 9 +---- 4 files changed, 16 insertions(+), 39 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 657477d34..b592982cb 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -167,8 +167,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; #define NPPM_MAKECURRENTBUFFERDIRTY (NPPMSG + 44) //BOOL NPPM_MAKECURRENTBUFFERDIRTY(0, 0) - #define NPPM_GETENABLETHEMETEXTUREFUNC (NPPMSG + 45) - //BOOL NPPM_GETENABLETHEMETEXTUREFUNC(0, 0) + #define NPPM_GETENABLETHEMETEXTUREFUNC_DEPRECATED (NPPMSG + 45) + //BOOL NPPM_GETENABLETHEMETEXTUREFUNC(0, 0) -- DEPRECATED : use EnableThemeDialogTexture from uxtheme.h instead #define NPPM_GETPLUGINSCONFIGDIR (NPPMSG + 46) //INT NPPM_GETPLUGINSCONFIGDIR(int strLen, TCHAR *str) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index fffe1cd8a..2da71534d 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -17,6 +17,7 @@ #include #include +#include // for EnableThemeDialogTexture #include "Notepad_plus_Window.h" #include "TaskListDlg.h" #include "ImageListSet.h" @@ -2658,9 +2659,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return TRUE; } - case NPPM_GETENABLETHEMETEXTUREFUNC: + case NPPM_GETENABLETHEMETEXTUREFUNC_DEPRECATED: { - return (LRESULT)nppParam.getEnableThemeDlgTexture(); + return reinterpret_cast(&EnableThemeDialogTexture); } case NPPM_GETPLUGINSCONFIGDIR: diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 373374a60..bfe835679 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -991,8 +991,6 @@ NppParameters::~NppParameters() delete _LRFileList[i]; for (int i = 0 ; i < _nbUserLang ; ++i) delete _userLangArray[i]; - if (_hUXTheme) - FreeLibrary(_hUXTheme); for (std::vector::iterator it = _pXmlExternalLexerDoc.begin(), end = _pXmlExternalLexerDoc.end(); it != end; ++it ) delete (*it); @@ -1221,20 +1219,6 @@ bool NppParameters::load() } } - //-------------------------------------// - // Transparent function for w2k and xp // - //-------------------------------------// - HMODULE hUser32 = ::GetModuleHandle(TEXT("User32")); - if (hUser32) - _transparentFuncAddr = (WNDPROC)::GetProcAddress(hUser32, "SetLayeredWindowAttributes"); - - //---------------------------------------------// - // Dlg theme texture function for xp and vista // - //---------------------------------------------// - _hUXTheme = ::LoadLibraryEx(TEXT("uxtheme.dll"), nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (_hUXTheme) - _enableThemeDialogTextureFuncAddr = (WNDPROC)::GetProcAddress(_hUXTheme, "EnableThemeDialogTexture"); - //--------------------------// // langs.xml : for per user // //--------------------------// @@ -1619,7 +1603,7 @@ void NppParameters::destroyInstance() delete _pXmlUserStylerDoc; //delete _pXmlUserLangDoc; will be deleted in the vector - for (auto l : _pXmlUserLangsDoc) + for (auto& l : _pXmlUserLangsDoc) { delete l._udlXmlDoc; } @@ -1651,22 +1635,19 @@ void NppParameters::setWorkSpaceFilePath(int i, const TCHAR* wsFile) void NppParameters::removeTransparent(HWND hwnd) { - if (hwnd != NULL) - ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) & ~0x00080000); + if (hwnd != nullptr) + ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED); } void NppParameters::SetTransparent(HWND hwnd, int percent) { - if (nullptr != _transparentFuncAddr) - { - ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) | 0x00080000); - if (percent > 255) - percent = 255; - if (percent < 0) - percent = 0; - _transparentFuncAddr(hwnd, 0, percent, 0x00000002); - } + ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ::GetWindowLongPtr(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED); + if (percent > 255) + percent = 255; + else if (percent < 0) + percent = 0; + ::SetLayeredWindowAttributes(hwnd, 0, static_cast(percent), LWA_ALPHA); } diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 699f6ad2f..e6bd6f17a 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1272,7 +1272,7 @@ public: bool themeNameExists(const TCHAR *themeName) { for (size_t i = 0; i < _themeList.size(); ++i ) { - auto themeNameOnList = getElementFromIndex(i).first; + auto& themeNameOnList = getElementFromIndex(i).first; if (lstrcmp(themeName, themeNameOnList.c_str()) == 0) return true; } @@ -1545,7 +1545,7 @@ public: TiXmlDocument * getCustomizedToolIcons() const {return _pXmlToolIconsDoc;}; bool isTransparentAvailable() const { - return (_transparentFuncAddr != NULL); + return (_winVersion >= WV_VISTA); } // 0 <= percent < 256 @@ -1645,7 +1645,6 @@ public: }; int langTypeToCommandID(LangType lt) const; - WNDPROC getEnableThemeDlgTexture() const {return _enableThemeDialogTextureFuncAddr;}; struct FindDlgTabTitiles final { generic_string _find; @@ -1829,10 +1828,6 @@ private: std::vector _fontlist; std::vector _blacklist; - HMODULE _hUXTheme = nullptr; - - WNDPROC _transparentFuncAddr = nullptr; - WNDPROC _enableThemeDialogTextureFuncAddr = nullptr; bool _isLocal = false; bool _isx64 = false; // by default 32-bit bool _isCloud = false;