Use undocumented dpi API to support win7
Fix https://github.com/notepad-plus-plus/notepad-plus-plus/pull/14818#issuecomment-1993472569 Close #14855
This commit is contained in:
parent
2e4ad67dff
commit
c8a2bcb6b0
|
@ -41,7 +41,7 @@ CXXFLAGS := -include $(GCC_DIRECTORY)/gcc-fixes.h -std=c++20
|
|||
RC := $(CROSS_COMPILE)windres
|
||||
RCFLAGS :=
|
||||
CPP_PATH := $(SCINTILLA_DIRECTORY)/include $(LEXILLA_DIRECTORY)/include
|
||||
CPP_DEFINE := UNICODE _UNICODE OEMRESOURCE NOMINMAX _WIN32_WINNT=_WIN32_WINNT_WIN10 NTDDI_VERSION=NTDDI_WIN10_RS5 TIXML_USE_STL TIXMLA_USE_STL
|
||||
CPP_DEFINE := UNICODE _UNICODE OEMRESOURCE NOMINMAX _WIN32_WINNT=_WIN32_WINNT_WIN7 NTDDI_VERSION=NTDDI_WIN7 TIXML_USE_STL TIXMLA_USE_STL
|
||||
LD := $(CXX)
|
||||
LDFLAGS := -municode -mwindows
|
||||
LD_PATH :=
|
||||
|
|
|
@ -395,13 +395,13 @@ IF (WIN32)
|
|||
if ( MSVC )
|
||||
#do not use for mingw builds
|
||||
SET(CMAKE_CXX_FLAGS "/EHa /MP /W4")
|
||||
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_WIN10 -DNTDDI_VERSION=NTDDI_WIN10_RS5 -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING )
|
||||
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_WIN7 -DNTDDI_VERSION=NTDDI_WIN7 -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING )
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
|
||||
else ( MSVC )
|
||||
# For possible MinGW compilation
|
||||
SET(CMAKE_CXX_FLAGS "-include../gcc/gcc-fixes.h -std=c++20 -fpermissive -municode")
|
||||
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_WIN10 -DNTDDI_VERSION=NTDDI_WIN10_RS5 -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE)
|
||||
SET(defs -DUNICODE -D_UNICODE -D_WIN32_WINNT=_WIN32_WINNT_WIN7 -DNTDDI_VERSION=NTDDI_WIN7 -D_USE_64BIT_TIME_T -DTIXML_USE_STL -DTIXMLA_USE_STL -DNOMINMAX -DOEMRESOURCE)
|
||||
endif ( MSVC )
|
||||
ENDIF (WIN32)
|
||||
|
||||
|
|
|
@ -1600,20 +1600,10 @@ namespace NppDarkMode
|
|||
void setMetricsForDpi(UINT dpi)
|
||||
{
|
||||
_dpi = dpi;
|
||||
if (NppDarkMode::isWindows10())
|
||||
{
|
||||
_xEdge = ::GetSystemMetricsForDpi(SM_CXEDGE, _dpi);
|
||||
_yEdge = ::GetSystemMetricsForDpi(SM_CYEDGE, _dpi);
|
||||
_xScroll = ::GetSystemMetricsForDpi(SM_CXVSCROLL, _dpi);
|
||||
_yScroll = ::GetSystemMetricsForDpi(SM_CYVSCROLL, _dpi);
|
||||
}
|
||||
else
|
||||
{
|
||||
_xEdge = DPIManagerV2::scale(::GetSystemMetrics(SM_CXEDGE), _dpi);
|
||||
_yEdge = DPIManagerV2::scale(::GetSystemMetrics(SM_CYEDGE), _dpi);
|
||||
_xScroll = DPIManagerV2::scale(::GetSystemMetrics(SM_CXVSCROLL), _dpi);
|
||||
_yScroll = DPIManagerV2::scale(::GetSystemMetrics(SM_CYVSCROLL), _dpi);
|
||||
}
|
||||
_xEdge = DPIManagerV2::getSystemMetricsForDpi(SM_CXEDGE, _dpi);
|
||||
_yEdge = DPIManagerV2::getSystemMetricsForDpi(SM_CYEDGE, _dpi);
|
||||
_xScroll = DPIManagerV2::getSystemMetricsForDpi(SM_CXVSCROLL, _dpi);
|
||||
_yScroll = DPIManagerV2::getSystemMetricsForDpi(SM_CYVSCROLL, _dpi);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -17,11 +17,54 @@
|
|||
|
||||
#include "dpiManagerV2.h"
|
||||
|
||||
template <typename P>
|
||||
bool ptrFn(HMODULE handle, P& pointer, const char* name)
|
||||
{
|
||||
auto p = reinterpret_cast<P>(::GetProcAddress(handle, name));
|
||||
if (p != nullptr)
|
||||
{
|
||||
pointer = p;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
using fnGetDpiForSystem = UINT (WINAPI*)();
|
||||
using fnGetDpiForWindow = UINT (WINAPI*)(HWND);
|
||||
using fnGetSystemMetricsForDpi = int (WINAPI*)(int, UINT);
|
||||
using fnSystemParametersInfoForDpi = BOOL(WINAPI*)(UINT, UINT, PVOID, UINT, UINT);
|
||||
|
||||
fnGetDpiForSystem _fnGetDpiForSystem = nullptr;
|
||||
fnGetDpiForWindow _fnGetDpiForWindow = nullptr;
|
||||
fnGetSystemMetricsForDpi _fnGetSystemMetricsForDpi = nullptr;
|
||||
fnSystemParametersInfoForDpi _fnSystemParametersInfoForDpi = nullptr;
|
||||
|
||||
void DPIManagerV2::initDpiAPI()
|
||||
{
|
||||
HMODULE hUser32 = ::GetModuleHandleW(L"user32.dll");
|
||||
if (hUser32)
|
||||
{
|
||||
ptrFn(hUser32, _fnGetDpiForSystem, "GetDpiForSystem");
|
||||
ptrFn(hUser32, _fnGetDpiForWindow, "GetDpiForWindow");
|
||||
ptrFn(hUser32, _fnGetSystemMetricsForDpi, "GetSystemMetricsForDpi");
|
||||
ptrFn(hUser32, _fnSystemParametersInfoForDpi, "SystemParametersInfoForDpi");
|
||||
}
|
||||
}
|
||||
|
||||
int DPIManagerV2::getSystemMetricsForDpi(int nIndex, UINT dpi)
|
||||
{
|
||||
if (_fnGetSystemMetricsForDpi != nullptr)
|
||||
{
|
||||
return _fnGetSystemMetricsForDpi(nIndex, dpi);
|
||||
}
|
||||
return DPIManagerV2::scale(::GetSystemMetrics(nIndex), dpi);
|
||||
}
|
||||
|
||||
UINT DPIManagerV2::getDpiForSystem()
|
||||
{
|
||||
if (NppDarkMode::isWindows10())
|
||||
if (_fnGetDpiForSystem != nullptr)
|
||||
{
|
||||
return ::GetDpiForSystem();
|
||||
return _fnGetDpiForSystem();
|
||||
}
|
||||
|
||||
UINT dpi = USER_DEFAULT_SCREEN_DPI;
|
||||
|
@ -36,9 +79,9 @@ UINT DPIManagerV2::getDpiForSystem()
|
|||
|
||||
UINT DPIManagerV2::getDpiForWindow(HWND hWnd)
|
||||
{
|
||||
if (NppDarkMode::isWindows10())
|
||||
if (_fnGetDpiForWindow != nullptr)
|
||||
{
|
||||
const auto dpi = ::GetDpiForWindow(hWnd);
|
||||
const auto dpi = _fnGetDpiForWindow(hWnd);
|
||||
if (dpi > 0)
|
||||
{
|
||||
return dpi;
|
||||
|
@ -66,8 +109,8 @@ LOGFONT DPIManagerV2::getDefaultGUIFontForDpi(UINT dpi, FontType type)
|
|||
LOGFONT lf{};
|
||||
NONCLIENTMETRICS ncm{};
|
||||
ncm.cbSize = sizeof(NONCLIENTMETRICS);
|
||||
if (NppDarkMode::isWindows10()
|
||||
&& (::SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi) != FALSE))
|
||||
if (_fnSystemParametersInfoForDpi != nullptr
|
||||
&& (_fnSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi) != FALSE))
|
||||
{
|
||||
result = 2;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
|
||||
#pragma once
|
||||
#include "NppDarkMode.h"
|
||||
#include <windows.h>
|
||||
|
||||
class DPIManagerV2
|
||||
{
|
||||
|
@ -28,6 +28,10 @@ public:
|
|||
|
||||
enum class FontType { menu, status, message, caption, smcaption };
|
||||
|
||||
static void initDpiAPI();
|
||||
|
||||
static int getSystemMetricsForDpi(int nIndex, UINT dpi);
|
||||
|
||||
static UINT getDpiForSystem();
|
||||
static UINT getDpiForWindow(HWND hWnd);
|
||||
static UINT getDpiForParent(HWND hWnd) {
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "MiniDumper.h" //Write dump files
|
||||
#include "verifySignedfile.h"
|
||||
#include "NppDarkMode.h"
|
||||
#include "dpiManagerV2.h"
|
||||
#include <memory>
|
||||
|
||||
typedef std::vector<std::wstring> ParamVector;
|
||||
|
@ -502,6 +503,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance
|
|||
NppGUI & nppGui = nppParameters.getNppGUI();
|
||||
|
||||
NppDarkMode::initDarkMode();
|
||||
DPIManagerV2::initDpiAPI();
|
||||
|
||||
bool doUpdateNpp = nppGui._autoUpdateOpt._doAutoUpdate;
|
||||
bool doUpdatePluginList = nppGui._autoUpdateOpt._doAutoUpdate;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<ItemDefinitionGroup Label="Globals">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\MISC\md5;..\src\MISC\sha1;..\src\MISC\sha2;..\src\MISC\sha512;..\src\MISC\SysMsg;..\src\ScintillaComponent;..\src\Win32Explr;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\DocumentMap;..\src\WinControls\FileBrowser;..\src\WinControls\FindCharsInRange;..\src\WinControls\FunctionList;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\PluginsAdmin;..\src\WinControls\Preference;..\src\WinControls\ProjectPanel;..\src\WinControls\ReadDirectoryChanges;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\TreeView;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\WindowsDlg;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_WIN10;NTDDI_VERSION=NTDDI_WIN10_RS5;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_WIN7;NTDDI_VERSION=NTDDI_WIN7;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ExceptionHandling>Async</ExceptionHandling>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
|
|
Loading…
Reference in New Issue