user: Make SwitchToThisWindow pass this test
Neil Rashbrook
neil at parkwaycc.co.uk
Tue Sep 5 03:30:42 CDT 2006
#include <windows.h>
#include "wine/test.h"
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 }
};
START_TEST(sttw)
{
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 );
ok( hwndfront != NULL,
"[%d] window relative z-order incorrect\n", i);
}
}
}
-------------- next part --------------
--- dlls/user/winpos.c Mon Sep 4 11:59:52 2006
+++ dlls/user/winpos.c Mon Sep 4 14:41:01 2006
@@ -152,7 +152,20 @@
*/
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 ( !( GetWindowLong( 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