mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-20 23:07:55 +08:00
28 lines
700 B
C++
28 lines
700 B
C++
|
#include "pch.h"
|
||
|
#include "util.h"
|
||
|
|
||
|
#include <common/dpi_aware.h>
|
||
|
|
||
|
typedef BOOL(WINAPI* GetDpiForMonitorInternalFunc)(HMONITOR, UINT, UINT*, UINT*);
|
||
|
UINT GetDpiForMonitor(HMONITOR monitor) noexcept
|
||
|
{
|
||
|
UINT dpi{};
|
||
|
if (wil::unique_hmodule user32{ LoadLibrary(L"user32.dll") })
|
||
|
{
|
||
|
if (auto func = reinterpret_cast<GetDpiForMonitorInternalFunc>(GetProcAddress(user32.get(), "GetDpiForMonitorInternal")))
|
||
|
{
|
||
|
func(monitor, 0, &dpi, &dpi);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (dpi == 0)
|
||
|
{
|
||
|
if (wil::unique_hdc hdc{ GetDC(nullptr) })
|
||
|
{
|
||
|
dpi = GetDeviceCaps(hdc.get(), LOGPIXELSX);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return (dpi == 0) ? DPIAware::DEFAULT_DPI : dpi;
|
||
|
}
|