mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
added convert rect
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
#include "dpi_aware.h"
|
#include "dpi_aware.h"
|
||||||
|
|
||||||
#include "monitors.h"
|
#include "monitors.h"
|
||||||
#include <ShellScalingApi.h>
|
#include <ShellScalingApi.h>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
namespace DPIAware
|
namespace DPIAware
|
||||||
{
|
{
|
||||||
@@ -60,6 +62,24 @@ namespace DPIAware
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Convert(HMONITOR monitor_handle, RECT& rect)
|
||||||
|
{
|
||||||
|
if (monitor_handle == NULL)
|
||||||
|
{
|
||||||
|
const POINT ptZero = { 0, 0 };
|
||||||
|
monitor_handle = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT dpi_x, dpi_y;
|
||||||
|
if (GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y) == S_OK)
|
||||||
|
{
|
||||||
|
rect.left = static_cast<long>(std::round(rect.left * static_cast<float>(dpi_x) / DEFAULT_DPI));
|
||||||
|
rect.right = static_cast<long>(std::round(rect.right * static_cast<float>(dpi_x) / DEFAULT_DPI));
|
||||||
|
rect.top = static_cast<long>(std::round(rect.top * static_cast<float>(dpi_y) / DEFAULT_DPI));
|
||||||
|
rect.bottom = static_cast<long>(std::round(rect.bottom * static_cast<float>(dpi_y) / DEFAULT_DPI));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ConvertByCursorPosition(float& width, float& height)
|
void ConvertByCursorPosition(float& width, float& height)
|
||||||
{
|
{
|
||||||
HMONITOR targetMonitor = nullptr;
|
HMONITOR targetMonitor = nullptr;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace DPIAware
|
|||||||
HRESULT GetScreenDPIForPoint(POINT p, UINT& dpi);
|
HRESULT GetScreenDPIForPoint(POINT p, UINT& dpi);
|
||||||
HRESULT GetScreenDPIForCursor(UINT& dpi);
|
HRESULT GetScreenDPIForCursor(UINT& dpi);
|
||||||
void Convert(HMONITOR monitor_handle, float& width, float& height);
|
void Convert(HMONITOR monitor_handle, float& width, float& height);
|
||||||
|
void Convert(HMONITOR monitor_handle, RECT& rect);
|
||||||
void ConvertByCursorPosition(float& width, float& height);
|
void ConvertByCursorPosition(float& width, float& height);
|
||||||
void InverseConvert(HMONITOR monitor_handle, float& width, float& height);
|
void InverseConvert(HMONITOR monitor_handle, float& width, float& height);
|
||||||
void EnableDPIAwarenessForThisProcess();
|
void EnableDPIAwarenessForThisProcess();
|
||||||
|
|||||||
Reference in New Issue
Block a user