|
4 | 4 | #pragma once |
5 | 5 |
|
6 | 6 | #include <Windows.h> |
7 | | -#include <ShellScalingApi.h> |
8 | 7 |
|
9 | 8 | #include <shobjidl_core.h> |
10 | 9 |
|
@@ -351,17 +350,32 @@ int WindowManager::IsDocked() { |
351 | 350 | return is_docked_; |
352 | 351 | } |
353 | 352 |
|
354 | | -double WindowManager::GetDpiForHwnd(HWND hWnd) |
355 | | -{ |
356 | | - auto monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); |
357 | | - UINT newDpiX; |
358 | | - UINT newDpiY; |
359 | | - if (FAILED(GetDpiForMonitor(monitor, MONITOR_DPI_TYPE::MDT_EFFECTIVE_DPI, &newDpiX, &newDpiY))) |
360 | | - { |
361 | | - newDpiX = 96; |
362 | | - newDpiY = 96; |
363 | | - } |
364 | | - return ((double) newDpiX); |
| 353 | +double WindowManager::GetDpiForHwnd(HWND hWnd) { |
| 354 | + auto monitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST); |
| 355 | + UINT newDpiX = 96; // Default values |
| 356 | + UINT newDpiY = 96; |
| 357 | + |
| 358 | + // Dynamically load shcore.dll and get the GetDpiForMonitor function address |
| 359 | + // We need to do this to ensure Windows 7 support |
| 360 | + HMODULE shcore = LoadLibrary(TEXT("shcore.dll")); |
| 361 | + if (shcore) { |
| 362 | + typedef HRESULT (*GetDpiForMonitor)(HMONITOR, int, UINT*, UINT*); |
| 363 | + |
| 364 | + GetDpiForMonitor GetDpiForMonitorFunc = |
| 365 | + (GetDpiForMonitor)GetProcAddress(shcore, "GetDpiForMonitor"); |
| 366 | + |
| 367 | + if (GetDpiForMonitorFunc) { |
| 368 | + // Use the loaded function if available |
| 369 | + const int MDT_EFFECTIVE_DPI = 0; |
| 370 | + if (FAILED(GetDpiForMonitorFunc(monitor, MDT_EFFECTIVE_DPI, &newDpiX, &newDpiY))) { |
| 371 | + // If it fails, set the default values again |
| 372 | + newDpiX = 96; |
| 373 | + newDpiY = 96; |
| 374 | + } |
| 375 | + } |
| 376 | + FreeLibrary(shcore); |
| 377 | + } |
| 378 | + return ((double) newDpiX); |
365 | 379 | } |
366 | 380 |
|
367 | 381 | void WindowManager::Dock(const flutter::EncodableMap& args) { |
|
0 commit comments