From d7cd5587df5c0dfc6a5b0b9586b0feee28ee0de8 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Tue, 18 May 2021 17:11:02 +0800 Subject: [PATCH] user32: Optimize getting monitor count with GetSystemMetrics(). This saves calls to GetMonitorInfo(). Signed-off-by: Zhiyi Zhang Signed-off-by: Alexandre Julliard --- 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: