Skip to content

Commit 5807a96

Browse files
authored
feat: restore Windows 7 support (#388)
1 parent 245f855 commit 5807a96

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

windows/window_manager.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#pragma once
55

66
#include <Windows.h>
7-
#include <ShellScalingApi.h>
87

98
#include <shobjidl_core.h>
109

@@ -351,17 +350,32 @@ int WindowManager::IsDocked() {
351350
return is_docked_;
352351
}
353352

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);
365379
}
366380

367381
void WindowManager::Dock(const flutter::EncodableMap& args) {

0 commit comments

Comments
 (0)