Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/user32/tests/monitor.c | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/dlls/user32/tests/monitor.c b/dlls/user32/tests/monitor.c index 2ca6e9ece84..5e4cc9d154f 100644 --- a/dlls/user32/tests/monitor.c +++ b/dlls/user32/tests/monitor.c @@ -1510,10 +1510,21 @@ static BOOL CALLBACK test_EnumDisplayMonitors_invalid_handle_cb(HMONITOR monitor return TRUE; }
+static BOOL CALLBACK test_EnumDisplayMonitors_count(HMONITOR monitor, HDC hdc, LPRECT rect, + LPARAM lparam) +{ + INT *count = (INT *)lparam; + ++(*count); + return TRUE; +} + static void test_EnumDisplayMonitors(void) { + static const DWORD DESKTOP_ALL_ACCESS = 0x01ff; + HWINSTA winstation, old_winstation; + HDESK desktop, old_desktop; + INT count, old_count; DWORD error; - INT count; BOOL ret;
ret = EnumDisplayMonitors(NULL, NULL, test_EnumDisplayMonitors_normal_cb, 0); @@ -1534,6 +1545,45 @@ static void test_EnumDisplayMonitors(void) else ok(ret, "EnumDisplayMonitors failed.\n"); ok(error == 0xdeadbeef, "Expected error %#x, got %#x.\n", 0xdeadbeef, error); + + /* Test that monitor enumeration is not affected by window stations and desktops */ + old_winstation = GetProcessWindowStation(); + old_desktop = GetThreadDesktop(GetCurrentThreadId()); + old_count = GetSystemMetrics(SM_CMONITORS); + + count = 0; + ret = EnumDisplayMonitors(NULL, NULL, test_EnumDisplayMonitors_count, (LPARAM)&count); + ok(ret, "EnumDisplayMonitors failed, error %#x.\n", GetLastError()); + ok(count == old_count, "Expected %d, got %d.\n", old_count, count); + + winstation = CreateWindowStationW(NULL, 0, WINSTA_ALL_ACCESS, NULL); + ok(!!winstation && winstation != old_winstation, "CreateWindowStationW failed, error %#x.\n", GetLastError()); + ret = SetProcessWindowStation(winstation); + ok(ret, "SetProcessWindowStation failed, error %#x.\n", GetLastError()); + ok(winstation == GetProcessWindowStation(), "Expected %p, got %p.\n", GetProcessWindowStation(), winstation); + + desktop = CreateDesktopW(L"test_desktop", NULL, NULL, 0, DESKTOP_ALL_ACCESS, NULL); + ok(!!desktop && desktop != old_desktop, "CreateDesktopW failed, error %#x.\n", GetLastError()); + ret = SetThreadDesktop(desktop); + ok(ret, "SetThreadDesktop failed, error %#x.\n", GetLastError()); + ok(desktop == GetThreadDesktop(GetCurrentThreadId()), "Expected %p, got %p.\n", + GetThreadDesktop(GetCurrentThreadId()), desktop); + + count = GetSystemMetrics(SM_CMONITORS); + ok(count == old_count, "Expected %d, got %d.\n", old_count, count); + count = 0; + ret = EnumDisplayMonitors(NULL, NULL, test_EnumDisplayMonitors_count, (LPARAM)&count); + ok(ret, "EnumDisplayMonitors failed, error %#x.\n", GetLastError()); + ok(count == old_count, "Expected %d, got %d.\n", old_count, count); + + ret = SetProcessWindowStation(old_winstation); + ok(ret, "SetProcessWindowStation failed, error %#x.\n", GetLastError()); + ret = SetThreadDesktop(old_desktop); + ok(ret, "SetThreadDesktop failed, error %#x.\n", GetLastError()); + ret = CloseDesktop(desktop); + ok(ret, "CloseDesktop failed, error %#x.\n", GetLastError()); + ret = CloseWindowStation(winstation); + ok(ret, "CloseWindowStation failed, error %#x.\n", GetLastError()); }
static void test_QueryDisplayConfig_result(UINT32 flags,