[KBM Editor] Support WM_DPICHANGED event (#11015)

* [KBM Editor] Support WM_DPICHANGED event

* [spell checker] add term

* [KBM editor] properly cast new DPI value
This commit is contained in:
Enrico Giordani
2021-04-30 07:04:53 -07:00
committed by GitHub
parent fa0cfeccb9
commit 0c3ce81c94
7 changed files with 134 additions and 59 deletions

View File

@@ -5,34 +5,43 @@
namespace DPIAware
{
HRESULT GetScreenDPIForWindow(HWND hwnd, UINT& dpi_x, UINT& dpi_y)
HRESULT GetScreenDPIForMonitor(HMONITOR targetMonitor, UINT& dpi)
{
auto monitor_handle = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
dpi_x = 0;
dpi_y = 0;
if (monitor_handle != nullptr)
if (targetMonitor != nullptr)
{
return GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y);
UINT dummy = 0;
return GetDpiForMonitor(targetMonitor, MDT_EFFECTIVE_DPI, &dpi, &dummy);
}
else
{
dpi = DPIAware::DEFAULT_DPI;
return E_FAIL;
}
}
HRESULT GetScreenDPIForPoint(POINT p, UINT& dpi_x, UINT& dpi_y)
HRESULT GetScreenDPIForWindow(HWND hwnd, UINT& dpi)
{
auto monitor_handle = MonitorFromPoint(p, MONITOR_DEFAULTTONEAREST);
dpi_x = 0;
dpi_y = 0;
if (monitor_handle != nullptr)
auto targetMonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
return GetScreenDPIForMonitor(targetMonitor, dpi);
}
HRESULT GetScreenDPIForPoint(POINT point, UINT& dpi)
{
auto targetMonitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST);
return GetScreenDPIForMonitor(targetMonitor, dpi);
}
HRESULT GetScreenDPIForCursor(UINT& dpi)
{
HMONITOR targetMonitor = nullptr;
POINT currentCursorPos{ 0 };
if (GetCursorPos(&currentCursorPos))
{
return GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y);
}
else
{
return E_FAIL;
targetMonitor = MonitorFromPoint(currentCursorPos, MONITOR_DEFAULTTOPRIMARY);
}
return GetScreenDPIForMonitor(targetMonitor, dpi);
}
void Convert(HMONITOR monitor_handle, int& width, int& height)
@@ -54,7 +63,7 @@ namespace DPIAware
void ConvertByCursorPosition(int& width, int& height)
{
HMONITOR targetMonitor = nullptr;
POINT currentCursorPos{};
POINT currentCursorPos{ 0 };
if (GetCursorPos(&currentCursorPos))
{
@@ -96,7 +105,7 @@ namespace DPIAware
{
if (AreDpiAwarenessContextsEqual(levels[i], system_returned_value))
{
return static_cast<AwarenessLevel>(i);
return static_cast<DPIAware::AwarenessLevel>(i);
}
}
return AwarenessLevel::UNAWARE;