mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
39 lines
932 B
C++
39 lines
932 B
C++
|
#include "windows_helper.hpp"
|
||
|
|
||
|
#ifdef USEWINSDK
|
||
|
|
||
|
namespace chatterino {
|
||
|
namespace util {
|
||
|
|
||
|
typedef enum MONITOR_DPI_TYPE {
|
||
|
MDT_EFFECTIVE_DPI = 0,
|
||
|
MDT_ANGULAR_DPI = 1,
|
||
|
MDT_RAW_DPI = 2,
|
||
|
MDT_DEFAULT = MDT_EFFECTIVE_DPI
|
||
|
} MONITOR_DPI_TYPE;
|
||
|
|
||
|
typedef HRESULT(CALLBACK *GetDpiForMonitor_)(HMONITOR, MONITOR_DPI_TYPE, UINT *, UINT *);
|
||
|
|
||
|
boost::optional<UINT> getWindowDpi(HWND hwnd)
|
||
|
{
|
||
|
static HINSTANCE shcore = LoadLibrary(L"Shcore.dll");
|
||
|
if (shcore != nullptr) {
|
||
|
if (auto getDpiForMonitor = GetDpiForMonitor_(GetProcAddress(shcore, "GetDpiForMonitor"))) {
|
||
|
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
|
||
|
|
||
|
UINT xScale, yScale;
|
||
|
|
||
|
getDpiForMonitor(monitor, MDT_DEFAULT, &xScale, &yScale);
|
||
|
|
||
|
return xScale;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return boost::none;
|
||
|
}
|
||
|
|
||
|
} // namespace util
|
||
|
} // namespace chatterino
|
||
|
|
||
|
#endif
|