2011-09-07 14:05:58 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS api tests
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* PURPOSE: Test for SetActiveWindow
|
|
|
|
* PROGRAMMERS: Giannis Adamopoulos
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <wine/test.h>
|
|
|
|
#include <windows.h>
|
2011-09-23 12:05:40 +00:00
|
|
|
#include "helper.h"
|
2011-09-24 11:55:19 +00:00
|
|
|
#include <undocuser.h>
|
2011-09-07 23:08:14 +00:00
|
|
|
|
2011-09-08 15:53:38 +00:00
|
|
|
HWND hWnd1, hWnd2, hWnd3, hWnd4;
|
|
|
|
|
2011-09-24 11:55:19 +00:00
|
|
|
/* FIXME: test for HWND_TOP, etc...*/
|
2011-09-23 12:05:40 +00:00
|
|
|
static int get_iwnd(HWND hWnd)
|
2011-09-08 15:53:38 +00:00
|
|
|
{
|
2011-09-23 12:05:40 +00:00
|
|
|
if(hWnd == hWnd1) return 1;
|
|
|
|
else if(hWnd == hWnd2) return 2;
|
|
|
|
else if(hWnd == hWnd3) return 3;
|
|
|
|
else if(hWnd == hWnd4) return 4;
|
|
|
|
else return 0;
|
2011-09-08 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT CALLBACK OwnerTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2011-09-24 11:55:19 +00:00
|
|
|
int iwnd = get_iwnd(hWnd);
|
|
|
|
|
|
|
|
if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message))
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
|
|
|
|
switch(message)
|
2011-09-08 15:53:38 +00:00
|
|
|
{
|
2011-10-04 17:53:43 +00:00
|
|
|
case WM_QUERYNEWPALETTE:
|
|
|
|
{
|
|
|
|
HDC hdc = GetDC(0);
|
|
|
|
int bits = GetDeviceCaps(hdc,BITSPIXEL);
|
|
|
|
ok( bits == 8 , "expected WM_QUERYNEWPALETTE only on 8bpp\n");
|
|
|
|
ReleaseDC(0, hdc);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-09-24 11:55:19 +00:00
|
|
|
case WM_IME_SETCONTEXT:
|
|
|
|
case WM_IME_NOTIFY :
|
|
|
|
case WM_GETICON :
|
|
|
|
case WM_GETTEXT:
|
|
|
|
break;
|
|
|
|
case WM_WINDOWPOSCHANGING:
|
|
|
|
case WM_WINDOWPOSCHANGED:
|
|
|
|
{
|
|
|
|
WINDOWPOS* pwp = (WINDOWPOS*)lParam;
|
|
|
|
ok(wParam==0,"expected wParam=0\n");
|
|
|
|
record_message(iwnd, message, SENT, get_iwnd(pwp->hwndInsertAfter), pwp->flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
record_message(iwnd, message, SENT, 0,0);
|
2011-09-08 15:53:38 +00:00
|
|
|
}
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2011-09-24 11:55:19 +00:00
|
|
|
static void FlushMessages()
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
|
|
|
|
{
|
|
|
|
int iwnd = get_iwnd(msg.hwnd);
|
|
|
|
if(!(msg.message > WM_USER || !iwnd || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
|
|
|
|
record_message(iwnd, msg.message, POST,0,0);
|
|
|
|
DispatchMessageA( &msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-08 15:53:38 +00:00
|
|
|
static void create_test_windows()
|
|
|
|
{
|
2011-09-23 12:05:40 +00:00
|
|
|
RegisterSimpleClass(OwnerTestProc, L"ownertest");
|
2011-09-08 15:53:38 +00:00
|
|
|
hWnd1 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
|
2011-09-07 23:08:14 +00:00
|
|
|
20, 20, 300, 300, NULL, NULL, 0, NULL);
|
2011-09-07 14:05:58 +00:00
|
|
|
|
2011-09-08 15:53:38 +00:00
|
|
|
hWnd2 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
|
2011-09-07 23:08:14 +00:00
|
|
|
20, 350, 300, 300, hWnd1, NULL, 0, NULL);
|
|
|
|
|
2011-09-08 15:53:38 +00:00
|
|
|
hWnd3 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
|
2011-09-07 14:05:58 +00:00
|
|
|
200, 200, 300, 300, NULL, NULL, 0, NULL);
|
|
|
|
|
2011-09-08 15:53:38 +00:00
|
|
|
hWnd4 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
|
2011-09-07 23:08:14 +00:00
|
|
|
250, 250, 200, 200, hWnd1, NULL, 0, NULL);
|
2011-09-08 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
2011-09-30 15:37:13 +00:00
|
|
|
static void set_default_zorder()
|
2011-09-08 15:53:38 +00:00
|
|
|
{
|
2011-09-30 15:37:13 +00:00
|
|
|
/* show the windows */
|
2011-09-07 14:05:58 +00:00
|
|
|
ShowWindow(hWnd1, SW_SHOW);
|
|
|
|
UpdateWindow(hWnd1);
|
|
|
|
ShowWindow(hWnd2, SW_SHOW);
|
|
|
|
UpdateWindow(hWnd2);
|
2011-09-07 23:08:14 +00:00
|
|
|
ShowWindow(hWnd3, SW_SHOW);
|
|
|
|
UpdateWindow(hWnd3);
|
|
|
|
ShowWindow(hWnd4, SW_SHOW);
|
|
|
|
UpdateWindow(hWnd4);
|
|
|
|
|
2011-09-30 15:37:13 +00:00
|
|
|
SetWindowPos(hWnd3, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
SetWindowPos(hWnd1, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
SetWindowPos(hWnd2, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
SetWindowPos(hWnd4, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
|
|
|
|
FlushMessages();
|
2011-09-08 15:53:38 +00:00
|
|
|
empty_message_cache();
|
2011-09-30 15:37:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_test_window()
|
|
|
|
{
|
|
|
|
DestroyWindow(hWnd1);
|
|
|
|
DestroyWindow(hWnd2);
|
|
|
|
DestroyWindow(hWnd3);
|
|
|
|
DestroyWindow(hWnd4);
|
|
|
|
UnregisterClassW(L"testClass", 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EXPECT_NEXT(hWnd1, hWnd2) \
|
|
|
|
ok(get_iwnd(GetWindow(hWnd1,GW_HWNDNEXT)) == get_iwnd(hWnd2), \
|
|
|
|
"After hwnd%d, expected hwnd%d not hwnd%d\n", \
|
|
|
|
get_iwnd(hWnd1), get_iwnd(hWnd2),get_iwnd(GetWindow(hWnd1,GW_HWNDNEXT)) )
|
|
|
|
|
|
|
|
#define EXPECT_CHAIN(A,B,C,D,X) \
|
|
|
|
EXPECT_NEXT(hWnd##A, hWnd##B); \
|
|
|
|
EXPECT_NEXT(hWnd##B, hWnd##C); \
|
|
|
|
EXPECT_NEXT(hWnd##C, hWnd##D); \
|
|
|
|
EXPECT_NEXT(hWnd##D, 0); \
|
|
|
|
EXPECT_ACTIVE(hWnd##X);
|
|
|
|
|
|
|
|
/* the actual test begins here */
|
|
|
|
|
|
|
|
MSG_ENTRY Activate1_chain[]=
|
|
|
|
{{4,WM_NCACTIVATE},
|
|
|
|
{4,WM_ACTIVATE},
|
|
|
|
{4,WM_WINDOWPOSCHANGING,SENT,0,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE},
|
|
|
|
{2,WM_WINDOWPOSCHANGING,SENT,4,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE},
|
|
|
|
{1,WM_WINDOWPOSCHANGING,SENT,2,SWP_NOMOVE | SWP_NOSIZE},
|
|
|
|
{1,WM_NCACTIVATE},
|
|
|
|
{1,WM_ACTIVATE},
|
|
|
|
{4,WM_KILLFOCUS},
|
|
|
|
{1,WM_SETFOCUS},
|
|
|
|
{0,0}};
|
|
|
|
|
|
|
|
MSG_ENTRY Activate2_chain[]=
|
|
|
|
{{1,WM_NCACTIVATE},
|
|
|
|
{1,WM_ACTIVATE},
|
|
|
|
{3,WM_WINDOWPOSCHANGING,SENT, 0, SWP_NOMOVE | SWP_NOSIZE},
|
|
|
|
{3,WM_WINDOWPOSCHANGED ,SENT, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
|
|
|
|
{3,WM_NCACTIVATE},
|
|
|
|
{3,WM_ACTIVATE},
|
|
|
|
{1,WM_KILLFOCUS},
|
|
|
|
{3,WM_SETFOCUS},
|
|
|
|
{0,0}};
|
|
|
|
|
|
|
|
MSG_ENTRY Activate3_chain[]=
|
|
|
|
{{3,WM_NCACTIVATE},
|
|
|
|
{3,WM_ACTIVATE},
|
|
|
|
{2,WM_WINDOWPOSCHANGING, SENT,0, SWP_NOMOVE | SWP_NOSIZE },
|
|
|
|
{4,WM_WINDOWPOSCHANGING, SENT,2, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE},
|
|
|
|
{1,WM_WINDOWPOSCHANGING, SENT,4, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE},
|
|
|
|
{2,WM_WINDOWPOSCHANGED, SENT,0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOCLIENTMOVE |SWP_NOCLIENTSIZE },
|
|
|
|
{4,WM_WINDOWPOSCHANGED, SENT,2, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
|
|
|
|
{1,WM_WINDOWPOSCHANGED, SENT,4, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
|
|
|
|
{2,WM_NCACTIVATE},
|
|
|
|
{2,WM_ACTIVATE},
|
|
|
|
{3,WM_KILLFOCUS},
|
|
|
|
{2,WM_SETFOCUS},
|
|
|
|
{0,0}};
|
|
|
|
|
|
|
|
MSG_ENTRY Activate4_chain[]=
|
|
|
|
{{2,WM_NCACTIVATE, },
|
|
|
|
{2,WM_ACTIVATE},
|
|
|
|
{2,WM_WINDOWPOSCHANGING, SENT ,0 ,SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE},
|
|
|
|
{4,WM_WINDOWPOSCHANGING, SENT, 2, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE} ,
|
|
|
|
{1,WM_WINDOWPOSCHANGING, SENT, 4, SWP_NOMOVE | SWP_NOSIZE},
|
|
|
|
{1,WM_NCACTIVATE},
|
|
|
|
{1,WM_ACTIVATE},
|
|
|
|
{2,WM_KILLFOCUS},
|
|
|
|
{1,WM_SETFOCUS},
|
|
|
|
{0,0}};
|
|
|
|
|
|
|
|
MSG_ENTRY Activate5_chain[]=
|
|
|
|
{{1,WM_NCACTIVATE, },
|
|
|
|
{1,WM_ACTIVATE},
|
|
|
|
{4,WM_WINDOWPOSCHANGING, SENT, 0 ,SWP_NOMOVE | SWP_NOSIZE},
|
|
|
|
{2,WM_WINDOWPOSCHANGING, SENT, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE},
|
|
|
|
{1,WM_WINDOWPOSCHANGING, SENT, 2, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE},
|
|
|
|
{4,WM_WINDOWPOSCHANGED, SENT, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
|
|
|
|
{4,WM_NCACTIVATE},
|
|
|
|
{4,WM_ACTIVATE},
|
|
|
|
{1,WM_KILLFOCUS},
|
|
|
|
{4,WM_SETFOCUS},
|
|
|
|
{0,0}};
|
|
|
|
|
|
|
|
/*
|
|
|
|
some notes about this testcase:
|
|
|
|
from the expected series of messages it is obbvious that SetActiveWindow uses SetWindowPos.
|
|
|
|
So the big question is, that if this behaviour (of changing the z order of owner and owned windows)
|
|
|
|
is implemented in SetActiveWindow or SetWindowPos.
|
|
|
|
More tests reveal that calling SetWindowPos like this, has the same effect in the zorder:
|
|
|
|
SetWindowPos(hWndX, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
|
|
However if it is called like this it does NOT change the z-order of owner or owned windows:
|
|
|
|
SetWindowPos(hWndX, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
So the conclusion is that SetActiveWindow calls Begin/Defer/EndDeferWindow pos
|
|
|
|
moving all affected windows in a batch move operation
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Test_OwnerWindows()
|
|
|
|
{
|
|
|
|
SetCursorPos(0,0);
|
|
|
|
|
|
|
|
create_test_windows();
|
|
|
|
set_default_zorder();
|
2011-09-07 23:08:14 +00:00
|
|
|
|
2011-09-30 15:37:13 +00:00
|
|
|
/* before we start testing SetActiveWindow we have to be sure they are on the ocrrect order*/
|
|
|
|
EXPECT_CHAIN(4,2,1,3,4);
|
|
|
|
|
|
|
|
/* move the windows on top in the following order 1 2 3 1 4 */
|
2011-09-08 15:53:38 +00:00
|
|
|
SetActiveWindow(hWnd1);
|
2011-09-24 11:55:19 +00:00
|
|
|
FlushMessages();
|
2011-09-30 15:37:13 +00:00
|
|
|
EXPECT_CHAIN(4,2,1,3,1);
|
2011-09-23 12:05:40 +00:00
|
|
|
COMPARE_CACHE(Activate1_chain);
|
2011-09-07 23:08:14 +00:00
|
|
|
|
|
|
|
SetActiveWindow(hWnd3);
|
2011-09-24 11:55:19 +00:00
|
|
|
FlushMessages();
|
2011-09-30 15:37:13 +00:00
|
|
|
EXPECT_CHAIN(3,4,2,1,3);
|
2011-09-23 12:05:40 +00:00
|
|
|
COMPARE_CACHE(Activate2_chain);
|
2011-09-07 14:05:58 +00:00
|
|
|
|
2011-09-07 23:08:14 +00:00
|
|
|
SetActiveWindow(hWnd2);
|
2011-09-24 11:55:19 +00:00
|
|
|
FlushMessages();
|
2011-09-30 15:37:13 +00:00
|
|
|
EXPECT_CHAIN(2,4,1,3,2);
|
2011-09-23 12:05:40 +00:00
|
|
|
COMPARE_CACHE(Activate3_chain);
|
2011-09-08 11:31:31 +00:00
|
|
|
|
|
|
|
SetActiveWindow(hWnd1);
|
2011-09-24 11:55:19 +00:00
|
|
|
FlushMessages();
|
2011-09-30 15:37:13 +00:00
|
|
|
EXPECT_CHAIN(2,4,1,3,1);
|
2011-09-23 12:05:40 +00:00
|
|
|
COMPARE_CACHE(Activate4_chain);
|
2011-09-30 15:37:13 +00:00
|
|
|
|
|
|
|
SetActiveWindow(hWnd4);
|
|
|
|
FlushMessages();
|
|
|
|
EXPECT_CHAIN(4,2,1,3,4);
|
|
|
|
/* in this test xp and 7 give different results :/ */
|
|
|
|
/*COMPARE_CACHE(Activate5_chain);*/
|
|
|
|
|
|
|
|
/* move the windows on top with the same order but now using SetWindowPos */
|
|
|
|
/* note: the zorder of windows change in the same way they change with SetActiveWindow */
|
|
|
|
set_default_zorder();
|
|
|
|
|
|
|
|
SetWindowPos(hWnd1, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(4,2,1,3,1);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd3, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(3,4,2,1,3);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd2, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(2,4,1,3,2);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd1, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(2,4,1,3,1);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd4, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(4,2,1,3,4);
|
|
|
|
|
|
|
|
/* now do the same thing one more time with SWP_NOACTIVATE */
|
|
|
|
set_default_zorder();
|
|
|
|
|
|
|
|
SetWindowPos(hWnd1, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(1,4,2,3,4);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd3, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(3,1,4,2,4);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd2, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(2,3,1,4,4);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd1, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
FlushMessages();
|
|
|
|
empty_message_cache();
|
|
|
|
EXPECT_CHAIN(1,2,3,4,4);
|
|
|
|
|
|
|
|
SetWindowPos(hWnd4, 0, 0,0,0,0, SWP_NOSENDCHANGING|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
|
|
|
|
FlushMessages();
|
|
|
|
EXPECT_CHAIN(4,1,2,3,4);
|
|
|
|
|
|
|
|
destroy_test_window();
|
2011-09-07 14:05:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(SetActiveWindow)
|
|
|
|
{
|
2011-09-30 15:37:13 +00:00
|
|
|
Test_OwnerWindows();
|
2011-09-07 14:05:58 +00:00
|
|
|
}
|