user: test and fix SwitchToThisWindow [3rd try]
Jan Zerebecki
jan.wine at zerebecki.de
Mon Sep 25 02:33:09 CDT 2006
If this patch is rejected from inclusion, please tell me why, as
I would have to ask anyway.
Based on feedback I added the test to the existing win test
instead of creating a new file.
From: Neil Rashbrook <neil at parkwaycc.co.uk>
Changelog:
user: test and fix SwitchToThisWindow
---
dlls/user/tests/win.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++
dlls/user/winpos.c | 15 +++++++
2 files changed, 118 insertions(+), 1 deletions(-)
diff --git a/dlls/user/tests/win.c b/dlls/user/tests/win.c
index 42c6ed5..49ba129 100644
--- a/dlls/user/tests/win.c
+++ b/dlls/user/tests/win.c
@@ -3873,6 +3873,108 @@ static void test_SetWindowLong(void)
}
}
+static void test_SwitchToThisWindow(void)
+{
+ DWORD exstyle[] = { WS_EX_OVERLAPPEDWINDOW, WS_EX_OVERLAPPEDWINDOW
+ | WS_EX_TOPMOST };
+
+ typedef struct sttw_test {
+ int show; /* SW_ flag for ShowWindow */
+ int topmost; /* whether to make the active window topmost */
+ int which; /* which window to switch to */
+ int flag; /* flag parameter */
+ int iconic; /* whether the window should be iconic */
+ int zoomed; /* whether the window should be zoomed */
+ int order; /* if not topmost, which window should be in front */
+ } sttw_test;
+
+ sttw_test sttw_tests[] = {
+ { SW_SHOWNORMAL, 0, 0, 0, 0, 0, 0 },
+ { SW_SHOWNORMAL, 0, 0, 1, 0, 0, 0 },
+ { SW_SHOWNORMAL, 0, 1, 0, 0, 0, 0 },
+ { SW_SHOWNORMAL, 0, 1, 1, 0, 0, 1 },
+ { SW_SHOWNORMAL, 1, 0, 0, 0, 0 },
+ { SW_SHOWNORMAL, 1, 0, 1, 0, 0 },
+ { SW_SHOWNORMAL, 1, 1, 0, 0, 0 },
+ { SW_SHOWNORMAL, 1, 1, 1, 0, 0 },
+ { SW_SHOWMINIMIZED, 0, 0, 0, 1, 0, 0 },
+ { SW_SHOWMINIMIZED, 0, 0, 1, 0, 0, 0 },
+ { SW_SHOWMINIMIZED, 0, 1, 0, 1, 0, 0 },
+ { SW_SHOWMINIMIZED, 0, 1, 1, 0, 0, 1 },
+ { SW_SHOWMINIMIZED, 1, 0, 0, 1, 0 },
+ { SW_SHOWMINIMIZED, 1, 0, 1, 0, 0 },
+ { SW_SHOWMINIMIZED, 1, 1, 0, 1, 0 },
+ { SW_SHOWMINIMIZED, 1, 1, 1, 0, 0 },
+ { SW_SHOWMAXIMIZED, 0, 0, 0, 0, 1, 0 },
+ { SW_SHOWMAXIMIZED, 0, 0, 1, 0, 1, 0 },
+ { SW_SHOWMAXIMIZED, 0, 1, 0, 0, 1, 0 },
+ { SW_SHOWMAXIMIZED, 0, 1, 1, 0, 1, 1 },
+ { SW_SHOWMAXIMIZED, 1, 0, 0, 0, 1 },
+ { SW_SHOWMAXIMIZED, 1, 0, 1, 0, 1 },
+ { SW_SHOWMAXIMIZED, 1, 1, 0, 0, 1 },
+ { SW_SHOWMAXIMIZED, 1, 1, 1, 0, 1 }
+ };
+
+ MSG msg;
+ int i;
+ HWND hwnd, hwndfront, hwndback, hwnds[2];
+
+ for (i = 0; i < sizeof(sttw_tests) / sizeof(sttw_test); ++i)
+ {
+ hwnds[0] = CreateWindow( "static", "", WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, NULL, NULL );
+ ShowWindow( hwnds[0], sttw_tests[i].show );
+ hwnds[1] = CreateWindowEx( exstyle[sttw_tests[i].topmost],
+ "static", "", WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, NULL, NULL );
+ ShowWindow( hwnds[1], sttw_tests[i].show );
+ SetActiveWindow( hwnds[1] );
+ SetForegroundWindow( hwnds[1] );
+ hwnd = hwnds[sttw_tests[i].which];
+ SwitchToThisWindow( hwnd, sttw_tests[i].flag );
+ /* On Windows, restoring a window is asynchronous. Give it 100ms */
+ while (PeekMessage( &msg, 0, 0, 0, TRUE ))
+ DispatchMessage( &msg );
+ Sleep(100);
+ while (PeekMessage( &msg, 0, 0, 0, TRUE ))
+ DispatchMessage( &msg );
+ ok( GetActiveWindow() == hwnd,
+ "[%d] switched window did not become active\n", i);
+ ok( GetForegroundWindow() == hwnd,
+ "[%d] switched window not in the foreground\n", i);
+ if (sttw_tests[i].iconic)
+ ok( IsIconic(hwnd),
+ "[%d] switched window unexpectedly iconic\n", i);
+ else
+ ok( !IsIconic(hwnd),
+ "[%d] switched window unexpectedly non-iconic\n", i);
+ if (sttw_tests[i].zoomed)
+ ok( IsZoomed(hwnd),
+ "[%d] switched window unexpectedly zoomed\n", i);
+ else
+ ok( !IsZoomed(hwnd),
+ "[%d] switched window unexpectedly non-zoomed\n", i);
+ if (sttw_tests[i].topmost)
+ ok( GetWindowLong( hwnds[1], GWL_EXSTYLE ) & WS_EX_TOPMOST,
+ "[%d] topmost window unexpectedly lost topmost\n", i);
+ else
+ {
+ hwndfront = hwnds[sttw_tests[i].order];
+ hwndback = hwnds[1 - sttw_tests[i].order];
+ while (hwndfront && hwndfront != hwndback)
+ hwndfront = GetWindow( hwndfront, GW_HWNDNEXT );
+ if(2==i||18==i) todo_wine ok( hwndfront != NULL,
+ "[%d] window relative z-order incorrect\n", i);
+ else ok( hwndfront != NULL,
+ "[%d] window relative z-order incorrect\n", i);
+ }
+ }
+}
+
START_TEST(win)
{
pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
@@ -3950,6 +4052,8 @@ START_TEST(win)
test_csparentdc();
test_SetWindowLong();
+ test_SwitchToThisWindow();
+
/* add the tests above this line */
UnhookWindowsHookEx(hhook);
}
diff --git a/dlls/user/winpos.c b/dlls/user/winpos.c
index 6bc9056..e78f484 100644
--- a/dlls/user/winpos.c
+++ b/dlls/user/winpos.c
@@ -152,7 +152,20 @@ UINT WINAPI ArrangeIconicWindows( HWND p
*/
void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
{
- ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
+ HWND hwndOld = GetForegroundWindow();
+ SetActiveWindow( hwnd );
+ SetForegroundWindow( hwnd );
+ if ( restore )
+ {
+ if ( IsIconic( hwnd ) )
+ ShowWindow( hwnd, SW_RESTORE );
+ }
+ else
+ {
+ if ( !( GetWindowLongW( hwndOld, GWL_EXSTYLE ) & WS_EX_TOPMOST ) )
+ SetWindowPos( hwndOld, HWND_BOTTOM, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
+ }
}
More information about the wine-patches
mailing list