ReactOS 0.4.16-dev-319-g6cf4263
CloseWindow.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for CloseWindow
5 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "precomp.h"
9
10static const WCHAR s_szClassName[] = L"CloseWindowTest";
11
13
18
19#define TIMER_INTERVAL 200
20
21static void
23{
24 if (uMsg == WM_TIMER || !s_bTracing)
25 return;
26
27 trace("uMsg:0x%04X, wParam:0x%08lX, lParam:0x%08lX\n", uMsg, (LONG)wParam, (LONG)lParam);
28
29 if (uMsg == WM_SYSCOMMAND)
30 {
32 }
33
34 if (uMsg == WM_NCACTIVATE)
36
37 if (uMsg == WM_WINDOWPOSCHANGING)
39
40 if (uMsg == WM_ACTIVATE)
42}
43
44// WM_TIMER
45static void
47{
48 KillTimer(hwnd, id);
49 switch (id)
50 {
51 //
52 // SetActiveWindow(GetDesktopWindow());
53 //
54 case 0:
57 ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
58 ok(GetActiveWindow() == NULL, "GetActiveWindow() != NULL\n");
59 ok(GetFocus() == NULL, "GetFocus() != NULL\n");
65 trace("CloseWindow(hwnd): tracing...\n");
66 ok(CloseWindow(hwnd), "CloseWindow failed\n");
67 break;
68 case 1:
69 ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
70 ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
71 ok(GetFocus() == NULL, "GetFocus() != NULL\n");
73 trace("CloseWindow(hwnd): tracing done\n");
74 ok(s_nWM_SYSCOMMAND == 0, "WM_SYSCOMMAND: %d\n", s_nWM_SYSCOMMAND);
75 ok(s_nWM_NCACTIVATE == 1, "WM_NCACTIVATE: %d\n", s_nWM_NCACTIVATE);
76 ok(s_nWM_WINDOWPOSCHANGING == 2, "WM_WINDOWPOSCHANGING: %d\n", s_nWM_WINDOWPOSCHANGING);
77 ok(s_nWM_ACTIVATE == 1, "WM_ACTIVATE: %d\n", s_nWM_ACTIVATE);
79 break;
80 //
81 // SetActiveWindow(hwnd);
82 //
83 case 2:
86 ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
87 ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
88 ok(GetFocus() == hwnd, "GetFocus() != hwnd\n");
94 trace("CloseWindow(hwnd): tracing...\n");
95 ok(CloseWindow(hwnd), "CloseWindow failed\n");
96 break;
97 case 3:
98 ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
99 ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
100 ok(GetFocus() == NULL, "GetFocus() != NULL\n");
102 trace("CloseWindow(hwnd): tracing done\n");
103 ok(s_nWM_SYSCOMMAND == 0, "WM_SYSCOMMAND: %d\n", s_nWM_SYSCOMMAND);
104 ok(s_nWM_NCACTIVATE == 0, "WM_NCACTIVATE: %d\n", s_nWM_NCACTIVATE);
105 ok(s_nWM_WINDOWPOSCHANGING == 1, "WM_WINDOWPOSCHANGING: %d\n", s_nWM_WINDOWPOSCHANGING);
106 ok(s_nWM_ACTIVATE == 0, "WM_ACTIVATE: %d\n", s_nWM_ACTIVATE);
108 break;
109 //
110 // SetForegroundWindow(hwnd);
111 //
112 case 4:
115 ok(GetForegroundWindow() == hwnd, "GetForegroundWindow() != hwnd\n");
116 ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
117 ok(GetFocus() == hwnd, "GetFocus() != hwnd\n");
121 s_nWM_ACTIVATE = 0;
123 trace("CloseWindow(hwnd): tracing...\n");
124 ok(CloseWindow(hwnd), "CloseWindow failed\n");
125 break;
126 case 5:
127 ok(GetForegroundWindow() == hwnd, "GetForegroundWindow() != hwnd\n");
128 ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
129 ok(GetFocus() == NULL, "GetFocus() != NULL\n");
131 trace("CloseWindow(hwnd): tracing done\n");
132 ok(s_nWM_SYSCOMMAND == 0, "WM_SYSCOMMAND: %d\n", s_nWM_SYSCOMMAND);
133 ok(s_nWM_NCACTIVATE == 0, "WM_NCACTIVATE: %d\n", s_nWM_NCACTIVATE);
134 ok(s_nWM_WINDOWPOSCHANGING == 1, "WM_WINDOWPOSCHANGING: %d\n", s_nWM_WINDOWPOSCHANGING);
135 ok(s_nWM_ACTIVATE == 0, "WM_ACTIVATE: %d\n", s_nWM_ACTIVATE);
137 break;
138 default: // finish
140 return;
141 }
142 SetTimer(hwnd, id + 1, TIMER_INTERVAL, NULL);
143}
144
145static LRESULT CALLBACK
147{
148 DoMessage(hwnd, uMsg, wParam, lParam);
149 switch (uMsg)
150 {
151 case WM_CREATE:
153 break;
154 case WM_TIMER:
156 break;
157 case WM_DESTROY:
159 break;
160 default:
161 return DefWindowProc(hwnd, uMsg, wParam, lParam);
162 }
163 return 0;
164}
165
167{
168 WNDCLASSW wc;
169 HICON hIcon;
170 HCURSOR hCursor;
171 ATOM atom;
172 HWND hwnd;
173 MSG msg;
174
175 ok(!CloseWindow(NULL), "CloseWindow(NULL) should be failed\n");
176
178 ok(hIcon != NULL, "hIcon was NULL\n");
179 hCursor = LoadCursor(NULL, IDC_ARROW);
180 ok(hCursor != NULL, "hCursor was NULL\n");
181
182 ZeroMemory(&wc, sizeof(wc));
185 wc.hIcon = hIcon;
186 wc.hCursor = hCursor;
187 wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
189 atom = RegisterClassW(&wc);
190 ok(atom != 0, "RegisterClassW failed\n");
191
192 if (!atom)
193 {
194 skip("atom is zero\n");
196 DestroyCursor(hCursor);
197 return;
198 }
199
200 hwnd = CreateWindowW(s_szClassName, L"CloseWindow testcase", WS_OVERLAPPEDWINDOW,
201 CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
203 ok(hwnd != NULL, "CreateWindowW failed\n");
204 trace("hwnd: %p\n", hwnd);
205
206 if (!hwnd)
207 {
208 skip("hwnd is NULL\n");
211 DestroyCursor(hCursor);
212 return;
213 }
214
217
218 while (GetMessage(&msg, NULL, 0, 0))
219 {
222 }
223
226 DestroyCursor(hCursor);
227}
static INT s_nWM_SYSCOMMAND
Definition: CloseWindow.c:14
static BOOL s_bTracing
Definition: CloseWindow.c:12
static const WCHAR s_szClassName[]
Definition: CloseWindow.c:10
static INT s_nWM_ACTIVATE
Definition: CloseWindow.c:17
#define TIMER_INTERVAL
Definition: CloseWindow.c:19
static void OnTimer(HWND hwnd, UINT id)
Definition: CloseWindow.c:46
static void DoMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: CloseWindow.c:22
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: CloseWindow.c:146
static INT s_nWM_NCACTIVATE
Definition: CloseWindow.c:15
static INT s_nWM_WINDOWPOSCHANGING
Definition: CloseWindow.c:16
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
WORD ATOM
Definition: dimm.idl:113
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CALLBACK
Definition: compat.h:35
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
unsigned int BOOL
Definition: ntddk_ex.h:94
static HICON
Definition: imagelist.c:80
HICON hIcon
Definition: msconfig.c:44
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
long LONG
Definition: pedump.c:60
#define DefWindowProc
Definition: ros2win.h:31
LPCWSTR lpszClassName
Definition: winuser.h:3188
HBRUSH hbrBackground
Definition: winuser.h:3186
HICON hIcon
Definition: winuser.h:3184
HINSTANCE hInstance
Definition: winuser.h:3183
WNDPROC lpfnWndProc
Definition: winuser.h:3180
HCURSOR hCursor
Definition: winuser.h:3185
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
#define ZeroMemory
Definition: winbase.h:1737
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
HICON HCURSOR
Definition: windef.h:299
#define SW_SHOWNORMAL
Definition: winuser.h:773
HWND WINAPI GetFocus(void)
Definition: window.c:1865
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
#define WM_SYSCOMMAND
Definition: winuser.h:1744
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:2741
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1664
#define WM_CREATE
Definition: winuser.h:1611
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define IDC_ARROW
Definition: winuser.h:687
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define IDI_APPLICATION
Definition: winuser.h:704
#define WM_ACTIVATE
Definition: winuser.h:1615
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:628
#define GetMessage
Definition: winuser.h:5802
#define WM_NCACTIVATE
Definition: winuser.h:1691
HWND WINAPI SetActiveWindow(_In_ HWND)
#define WM_TIMER
Definition: winuser.h:1745
#define LoadIcon
Definition: winuser.h:5825
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5824
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4319
#define CW_USEDEFAULT
Definition: winuser.h:225
#define SW_RESTORE
Definition: winuser.h:782
#define WM_DESTROY
Definition: winuser.h:1612
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
BOOL WINAPI CloseWindow(_In_ HWND)
#define DispatchMessage
Definition: winuser.h:5777
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
BOOL WINAPI DestroyWindow(_In_ HWND)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2105
#define COLOR_3DFACE
Definition: winuser.h:932
__wchar_t WCHAR
Definition: xmlstorage.h:180