|
|
@ -17,11 +17,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "dpiManagerV2.h"
|
|
|
|
#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()
|
|
|
|
UINT DPIManagerV2::getDpiForSystem()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (NppDarkMode::isWindows10())
|
|
|
|
if (_fnGetDpiForSystem != nullptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ::GetDpiForSystem();
|
|
|
|
return _fnGetDpiForSystem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UINT dpi = USER_DEFAULT_SCREEN_DPI;
|
|
|
|
UINT dpi = USER_DEFAULT_SCREEN_DPI;
|
|
|
@ -36,9 +79,9 @@ UINT DPIManagerV2::getDpiForSystem()
|
|
|
|
|
|
|
|
|
|
|
|
UINT DPIManagerV2::getDpiForWindow(HWND hWnd)
|
|
|
|
UINT DPIManagerV2::getDpiForWindow(HWND hWnd)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (NppDarkMode::isWindows10())
|
|
|
|
if (_fnGetDpiForWindow != nullptr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const auto dpi = ::GetDpiForWindow(hWnd);
|
|
|
|
const auto dpi = _fnGetDpiForWindow(hWnd);
|
|
|
|
if (dpi > 0)
|
|
|
|
if (dpi > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return dpi;
|
|
|
|
return dpi;
|
|
|
@ -66,8 +109,8 @@ LOGFONT DPIManagerV2::getDefaultGUIFontForDpi(UINT dpi, FontType type)
|
|
|
|
LOGFONT lf{};
|
|
|
|
LOGFONT lf{};
|
|
|
|
NONCLIENTMETRICS ncm{};
|
|
|
|
NONCLIENTMETRICS ncm{};
|
|
|
|
ncm.cbSize = sizeof(NONCLIENTMETRICS);
|
|
|
|
ncm.cbSize = sizeof(NONCLIENTMETRICS);
|
|
|
|
if (NppDarkMode::isWindows10()
|
|
|
|
if (_fnSystemParametersInfoForDpi != nullptr
|
|
|
|
&& (::SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi) != FALSE))
|
|
|
|
&& (_fnSystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi) != FALSE))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
result = 2;
|
|
|
|
result = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|