@@ -1331,17 +1331,17 @@ Rect2i DisplayServerWindows::screen_get_usable_rect(int p_screen) const {
13311331}
13321332
13331333typedef struct {
1334- int count ;
1334+ int current_index ;
13351335 int screen;
13361336 int dpi;
13371337} EnumDpiData;
13381338
1339- static int QueryDpiForMonitor (HMONITOR hmon, MONITOR_DPI_TYPE dpiType = MDT_DEFAULT ) {
1339+ static int QueryDpiForMonitor (HMONITOR hmon) {
13401340 int dpiX = 96 , dpiY = 96 ;
13411341
13421342 UINT x = 0 , y = 0 ;
13431343 if (hmon) {
1344- HRESULT hr = GetDpiForMonitor (hmon, dpiType , &x, &y);
1344+ HRESULT hr = GetDpiForMonitor (hmon, MDT_DEFAULT , &x, &y);
13451345 if (SUCCEEDED (hr) && (x > 0 ) && (y > 0 )) {
13461346 dpiX = (int )x;
13471347 dpiY = (int )y;
@@ -1367,23 +1367,25 @@ static int QueryDpiForMonitor(HMONITOR hmon, MONITOR_DPI_TYPE dpiType = MDT_DEFA
13671367
13681368static BOOL CALLBACK _MonitorEnumProcDpi (HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) {
13691369 EnumDpiData *data = (EnumDpiData *)dwData;
1370- if (data->count == data->screen ) {
1370+
1371+ data->current_index ++;
1372+
1373+ if (data->current_index == data->screen ) {
13711374 data->dpi = QueryDpiForMonitor (hMonitor);
1375+ return FALSE ;
13721376 }
1373-
1374- data->count ++;
13751377 return TRUE ;
13761378}
13771379
13781380int DisplayServerWindows::screen_get_dpi (int p_screen) const {
13791381 _THREAD_SAFE_METHOD_
13801382
13811383 p_screen = _get_screen_index (p_screen);
1382- int screen_count = get_screen_count ();
1383- ERR_FAIL_INDEX_V (p_screen, screen_count, 72 );
13841384
1385- EnumDpiData data = { 0 , p_screen, 72 };
1385+ EnumDpiData data = { - 1 , p_screen, 96 };
13861386 EnumDisplayMonitors (nullptr , nullptr , _MonitorEnumProcDpi, (LPARAM)&data);
1387+
1388+ ERR_FAIL_COND_V_MSG (data.current_index < p_screen, 96 , vformat (" Screen index %d out of range [0, %d]." , p_screen, data.current_index ));
13871389 return data.dpi ;
13881390}
13891391
0 commit comments