[IPHLPAPI_APITEST]
[reactos.git] / rostests / apitests / user32 / SetActiveWindow.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for SetActiveWindow
5 * PROGRAMMERS: Giannis Adamopoulos
6 */
7
8 #include <apitest.h>
9
10 #include <wingdi.h>
11 #include <winuser.h>
12 #include "helper.h"
13 #include <undocuser.h>
14
15 HWND hWnd1, hWnd2;
16
17 /* FIXME: test for HWND_TOP, etc...*/
18 static int get_iwnd(HWND hWnd)
19 {
20 if(hWnd == hWnd1) return 1;
21 else if(hWnd == hWnd2) return 2;
22 else return 0;
23 }
24
25 LRESULT CALLBACK OwnerTestProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
26 {
27 int iwnd = get_iwnd(hWnd);
28
29 if(message > WM_USER || !iwnd || IsDWmMsg(message) || IseKeyMsg(message))
30 return DefWindowProc(hWnd, message, wParam, lParam);
31
32 switch(message)
33 {
34 case WM_QUERYNEWPALETTE:
35 {
36 HDC hdc = GetDC(0);
37 int bits = GetDeviceCaps(hdc,BITSPIXEL);
38 ok( bits == 8 , "expected WM_QUERYNEWPALETTE only on 8bpp\n");
39 ReleaseDC(0, hdc);
40 return FALSE;
41 }
42 case WM_IME_SETCONTEXT:
43 case WM_IME_NOTIFY :
44 case WM_GETICON :
45 case WM_GETTEXT:
46 break;
47 case WM_WINDOWPOSCHANGING:
48 case WM_WINDOWPOSCHANGED:
49 {
50 WINDOWPOS* pwp = (WINDOWPOS*)lParam;
51 ok(wParam==0,"expected wParam=0\n");
52 RECORD_MESSAGE(iwnd, message, SENT, get_iwnd(pwp->hwndInsertAfter), pwp->flags);
53 break;
54 }
55 default:
56 RECORD_MESSAGE(iwnd, message, SENT, 0,0);
57 }
58 return DefWindowProc(hWnd, message, wParam, lParam);
59 }
60
61 static void FlushMessages()
62 {
63 MSG msg;
64
65 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
66 {
67 int iwnd = get_iwnd(msg.hwnd);
68 if(!(msg.message > WM_USER || !iwnd || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
69 RECORD_MESSAGE(iwnd, msg.message, POST,0,0);
70 DispatchMessageA( &msg );
71 }
72 }
73
74 static void create_test_windows()
75 {
76 RegisterSimpleClass(OwnerTestProc, L"ownertest");
77 hWnd1 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
78 20, 20, 300, 300, NULL, NULL, 0, NULL);
79
80 hWnd2 = CreateWindowW(L"ownertest", L"ownertest", WS_OVERLAPPEDWINDOW,
81 200, 200, 300, 300, NULL, NULL, 0, NULL);
82 }
83
84 static void set_default_zorder()
85 {
86 SetWindowPos(hWnd1, 0, 0,0,0,0, SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
87 SetWindowPos(hWnd2, 0, 0,0,0,0, SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOSIZE|SWP_SHOWWINDOW);
88
89 FlushMessages();
90 EMPTY_CACHE();
91 }
92
93 static void destroy_test_window()
94 {
95 DestroyWindow(hWnd1);
96 DestroyWindow(hWnd2);
97 UnregisterClassW(L"testClass", 0);
98 }
99
100 MSG_ENTRY activate2to1_chain[]={
101 {2,WM_NCACTIVATE},
102 {2,WM_ACTIVATE},
103 {1,WM_WINDOWPOSCHANGING, SENT,0, SWP_NOSIZE|SWP_NOMOVE},
104 {1,WM_WINDOWPOSCHANGED, SENT,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
105 {1,WM_NCACTIVATE},
106 {1,WM_ACTIVATE},
107 {2,WM_KILLFOCUS},
108 {1,WM_SETFOCUS},
109 {0,0}};
110
111 MSG_ENTRY activate1to2_chain[]={
112 {1,WM_NCACTIVATE},
113 {1,WM_ACTIVATE},
114 {2,WM_WINDOWPOSCHANGING, SENT,0, SWP_NOSIZE|SWP_NOMOVE},
115 {2,WM_WINDOWPOSCHANGED, SENT,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOCLIENTMOVE|SWP_NOCLIENTSIZE},
116 {2,WM_NCACTIVATE},
117 {2,WM_ACTIVATE},
118 {1,WM_KILLFOCUS},
119 {2,WM_SETFOCUS},
120 {0,0}};
121
122 void Test_msg_simple()
123 {
124 SetCursorPos(0,0);
125
126 create_test_windows();
127 set_default_zorder();
128
129 SetActiveWindow(hWnd1);
130 FlushMessages();
131 COMPARE_CACHE(activate2to1_chain);
132
133 SetActiveWindow(hWnd2);
134 FlushMessages();
135 COMPARE_CACHE(activate1to2_chain);
136
137 destroy_test_window();
138 }
139
140 START_TEST(SetActiveWindow)
141 {
142 Test_msg_simple();
143 }