[PATCH 1/6] user32: Optimize getting monitor count with GetSystemMetrics().

Zhiyi Zhang zzhang at codeweavers.com
Tue May 18 04:11:02 CDT 2021


This saves calls to GetMonitorInfo().

Signed-off-by: Zhiyi Zhang <zzhang at codeweavers.com>
---
 dlls/user32/sysparams.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 0b4dbfc2d78..7dc2a8df645 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -371,6 +371,22 @@ RECT get_virtual_screen_rect(void)
     return info.virtual_rect;
 }
 
+static BOOL CALLBACK get_monitor_count_proc( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp )
+{
+    INT *count = (INT *)lp;
+
+    ++(*count);
+    return TRUE;
+}
+
+static INT get_monitor_count(void)
+{
+    INT count = 0;
+
+    EnumDisplayMonitors( 0, NULL, get_monitor_count_proc, (LPARAM)&count );
+    return count;
+}
+
 static BOOL get_primary_adapter(WCHAR *name)
 {
     DISPLAY_DEVICEW dd;
@@ -2717,8 +2733,7 @@ INT WINAPI GetSystemMetrics( INT index )
         get_monitors_info( &info );
         return info.virtual_rect.bottom - info.virtual_rect.top;
     case SM_CMONITORS:
-        get_monitors_info( &info );
-        return info.count;
+        return get_monitor_count();
     case SM_SAMEDISPLAYFORMAT:
         return 1;
     case SM_IMMENABLED:
-- 
2.30.2




More information about the wine-devel mailing list