13bool AssignProcAddress(
HMODULE comBaseModule,
const char*
name,
T*& outProc) {
14 outProc =
reinterpret_cast<T*
>(GetProcAddress(comBaseModule,
name));
15 return *outProc !=
nullptr;
20class ScaleHelperWin32 {
27 HRESULT GetScaleFactorForMonitor(HMONITOR hmonitor,
28 DEVICE_SCALE_FACTOR*
scale)
const;
31 using GetScaleFactorForMonitor_ =
32 HRESULT __stdcall(HMONITOR hmonitor, DEVICE_SCALE_FACTOR*
scale);
34 GetScaleFactorForMonitor_* get_scale_factor_for_monitor_ =
nullptr;
36 HMODULE shlib_module_ =
nullptr;
37 bool scale_factor_for_monitor_supported_ =
false;
40ScaleHelperWin32::ScaleHelperWin32() {
41 if ((shlib_module_ = LoadLibraryA(
"Shcore.dll")) !=
nullptr) {
42 scale_factor_for_monitor_supported_ =
43 AssignProcAddress(shlib_module_,
"GetScaleFactorForMonitor",
44 get_scale_factor_for_monitor_);
48ScaleHelperWin32::~ScaleHelperWin32() {
49 if (shlib_module_ !=
nullptr) {
50 FreeLibrary(shlib_module_);
54HRESULT ScaleHelperWin32::GetScaleFactorForMonitor(
56 DEVICE_SCALE_FACTOR*
scale)
const {
57 if (hmonitor ==
nullptr ||
scale ==
nullptr) {
60 if (!scale_factor_for_monitor_supported_) {
61 *
scale = SCALE_100_PERCENT;
64 return get_scale_factor_for_monitor_(hmonitor,
scale);
67ScaleHelperWin32* GetHelper() {
68 static ScaleHelperWin32* helper =
new ScaleHelperWin32();
75 HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
76 DEVICE_SCALE_FACTOR
scale = DEVICE_SCALE_FACTOR_INVALID;
77 if (
SUCCEEDED(GetHelper()->GetScaleFactorForMonitor(monitor, &
scale))) {
84 switch (scale_factor) {
85 case SCALE_100_PERCENT:
87 case SCALE_120_PERCENT:
89 case SCALE_125_PERCENT:
91 case SCALE_140_PERCENT:
93 case SCALE_150_PERCENT:
95 case SCALE_160_PERCENT:
97 case SCALE_175_PERCENT:
99 case SCALE_180_PERCENT:
101 case SCALE_200_PERCENT:
103 case SCALE_225_PERCENT:
105 case SCALE_250_PERCENT:
107 case SCALE_300_PERCENT:
109 case SCALE_350_PERCENT:
111 case SCALE_400_PERCENT:
113 case SCALE_450_PERCENT:
115 case SCALE_500_PERCENT:
float GetScaleFactorForHWND(HWND hwnd)
float ScaleFactorToFloat(DEVICE_SCALE_FACTOR scale_factor)
DEF_SWITCHES_START aot vmservice shared library name