ReactOS  0.4.14-dev-999-g61c8d34
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 
10 static const WCHAR s_szClassName[] = L"CloseWindowTest";
11 
13 
14 static INT s_nWM_SYSCOMMAND = 0;
15 static INT s_nWM_NCACTIVATE = 0;
17 static INT s_nWM_ACTIVATE = 0;
18 
19 #define TIMER_INTERVAL 200
20 
21 static 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
45 static 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");
60  s_nWM_SYSCOMMAND = 0;
61  s_nWM_NCACTIVATE = 0;
63  s_nWM_ACTIVATE = 0;
64  s_bTracing = TRUE;
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");
72  s_bTracing = FALSE;
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");
89  s_nWM_SYSCOMMAND = 0;
90  s_nWM_NCACTIVATE = 0;
92  s_nWM_ACTIVATE = 0;
93  s_bTracing = TRUE;
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");
101  s_bTracing = FALSE;
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");
118  s_nWM_SYSCOMMAND = 0;
119  s_nWM_NCACTIVATE = 0;
121  s_nWM_ACTIVATE = 0;
122  s_bTracing = TRUE;
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");
130  s_bTracing = FALSE;
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 
145 static LRESULT CALLBACK
147 {
148  DoMessage(hwnd, uMsg, wParam, lParam);
149  switch (uMsg)
150  {
151  case WM_CREATE:
153  break;
154  case WM_TIMER:
155  OnTimer(hwnd, (UINT)wParam);
156  break;
157  case WM_DESTROY:
158  PostQuitMessage(0);
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));
183  wc.lpfnWndProc = WindowProc;
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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI CloseWindow(_In_ HWND)
#define DispatchMessage
Definition: winuser.h:5740
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
#define TRUE
Definition: types.h:120
START_TEST(CloseWindow)
Definition: CloseWindow.c:166
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
WORD ATOM
Definition: dimm.idl:113
static void OnTimer(HWND hwnd, UINT id)
Definition: CloseWindow.c:46
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
static INT s_nWM_SYSCOMMAND
Definition: CloseWindow.c:14
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:27
BOOL WINAPI UpdateWindow(_In_ HWND)
#define TIMER_INTERVAL
Definition: CloseWindow.c:19
#define ZeroMemory
Definition: winbase.h:1642
static const WCHAR s_szClassName[]
Definition: CloseWindow.c:10
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HICON HCURSOR
Definition: windef.h:299
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
static BOOL s_bTracing
Definition: CloseWindow.c:12
#define SW_RESTORE
Definition: winuser.h:773
BOOL WINAPI DestroyWindow(_In_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4291
int32_t INT
Definition: typedefs.h:57
WPARAM wParam
Definition: combotst.c:138
static void DoMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: CloseWindow.c:22
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define COLOR_3DFACE
Definition: winuser.h:919
static INT s_nWM_WINDOWPOSCHANGING
Definition: CloseWindow.c:16
HWND WINAPI SetActiveWindow(_In_ HWND)
#define WM_NCACTIVATE
Definition: winuser.h:1670
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
WNDPROC lpfnWndProc
Definition: winuser.h:3152
#define CW_USEDEFAULT
Definition: winuser.h:225
static INT s_nWM_ACTIVATE
Definition: CloseWindow.c:17
smooth NULL
Definition: ftsmooth.c:416
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:652
LPCWSTR lpszClassName
Definition: winuser.h:3160
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:2654
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_TIMER
Definition: winuser.h:1724
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1643
HICON hIcon
Definition: winuser.h:3156
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
static const WCHAR L[]
Definition: oid.c:1250
#define LoadCursor
Definition: winuser.h:5787
HCURSOR hCursor
Definition: winuser.h:3157
#define SW_SHOWNORMAL
Definition: winuser.h:764
#define WM_ACTIVATE
Definition: winuser.h:1594
HICON hIcon
Definition: msconfig.c:44
static INT s_nWM_NCACTIVATE
Definition: CloseWindow.c:15
HBRUSH hbrBackground
Definition: winuser.h:3158
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
#define GetMessage
Definition: winuser.h:5765
HINSTANCE hInstance
Definition: winuser.h:3155
#define skip(...)
Definition: atltest.h:64
#define msg(x)
Definition: auth_time.c:54
HWND WINAPI GetFocus(void)
Definition: window.c:1905
#define IDC_ARROW
Definition: winuser.h:682
#define WM_CREATE
Definition: winuser.h:1590
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
BOOL WINAPI SetForegroundWindow(_In_ HWND)
#define LoadIcon
Definition: winuser.h:5788
LONG_PTR LRESULT
Definition: windef.h:209
#define WM_SYSCOMMAND
Definition: winuser.h:1723
LPARAM lParam
Definition: combotst.c:139
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: CloseWindow.c:146
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)