ReactOS  0.4.15-dev-4920-g5fa8403
SwitchToThisWindow.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 SwitchToThisWindow
5  * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #include "precomp.h"
9 
10 static const WCHAR s_szClassName[] = L"SwitchTest";
11 
13 
16 static INT s_nWM_NCACTIVATE = 0;
18 static INT s_nWM_ACTIVATE = 0;
19 
20 #define TIMER_INTERVAL 200
21 
22 static const char *
24 {
25  static char s_buf[128];
26  DWORD dwRet = InSendMessageEx(NULL);
27  if (dwRet == ISMEX_NOSEND)
28  {
29  strcpy(s_buf, "ISMEX_NOSEND,");
30  return s_buf;
31  }
32  s_buf[0] = 0;
33  if (dwRet & ISMEX_CALLBACK)
34  strcat(s_buf, "ISMEX_CALLBACK,");
35  if (dwRet & ISMEX_NOTIFY)
36  strcat(s_buf, "ISMEX_NOTIFY,");
37  if (dwRet & ISMEX_REPLIED)
38  strcat(s_buf, "ISMEX_REPLIED,");
39  if (dwRet & ISMEX_SEND)
40  strcat(s_buf, "ISMEX_SEND,");
41  return s_buf;
42 }
43 
44 static void
46 {
47  if (uMsg == WM_TIMER || !s_bTracing)
48  return;
49 
50  trace("%s: uMsg:0x%04X, wParam:0x%08lX, lParam:0x%08lX, ISMEX_:%s\n",
51  (InSendMessage() ? "S" : "P"), uMsg, (LONG)wParam, (LONG)lParam,
52  DumpInSMEX());
53 
54  if (uMsg == WM_SYSCOMMAND) // 0x0112
55  {
56  ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
57  "InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
58  if (wParam == SC_RESTORE)
60  else
62  }
63 
64  if (uMsg == WM_NCACTIVATE) // 0x0086
65  {
66  ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
67  "InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
69  }
70 
71  if (uMsg == WM_WINDOWPOSCHANGING) // 0x0046
72  {
73  ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
74  "InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
76  }
77 
78  if (uMsg == WM_ACTIVATE) // 0x0006
79  {
80  ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
81  "InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
83  }
84 }
85 
86 // WM_TIMER
87 static void
89 {
90  KillTimer(hwnd, id);
91  switch (id)
92  {
93  //
94  // SwitchToThisWindow(TRUE)
95  //
96  case 0: // minimize
99  ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
100  ok(GetActiveWindow() == NULL, "GetActiveWindow() != NULL\n");
101  ok(GetFocus() == NULL, "GetFocus() != NULL\n");
102  CloseWindow(hwnd); // minimize
103  break;
104  case 1: // start tracing
105  ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
106  ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
107  ok(GetFocus() == NULL, "GetFocus() != NULL\n");
110  s_nWM_NCACTIVATE = 0;
112  s_nWM_ACTIVATE = 0;
113  s_bTracing = TRUE;
115  trace("SwitchToThisWindow(TRUE): tracing...\n");
116  break;
117  case 2: // tracing done
118  s_bTracing = FALSE;
119  trace("SwitchToThisWindow(TRUE): tracing done\n");
120  ok(GetForegroundWindow() == hwnd, "GetForegroundWindow() != hwnd\n");
121  ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
122  ok(GetFocus() == hwnd, "GetFocus() != hwnd\n");
123  ok(s_nWM_SYSCOMMAND_SC_RESTORE == 1, "WM_SYSCOMMAND SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_SC_RESTORE);
124  ok(!s_nWM_SYSCOMMAND_NOT_SC_RESTORE, "WM_SYSCOMMAND non-SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_NOT_SC_RESTORE);
125  ok(s_nWM_NCACTIVATE == 1, "WM_NCACTIVATE: %d\n", s_nWM_NCACTIVATE);
126  ok(s_nWM_WINDOWPOSCHANGING == 2, "WM_WINDOWPOSCHANGING: %d\n", s_nWM_WINDOWPOSCHANGING);
127  ok(s_nWM_ACTIVATE == 1, "WM_ACTIVATE: %d\n", s_nWM_ACTIVATE);
128  break;
129  //
130  // SwitchToThisWindow(FALSE)
131  //
132  case 3: // minimize
135  ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
136  ok(GetActiveWindow() == NULL, "GetActiveWindow() != NULL\n");
137  ok(GetFocus() == NULL, "GetFocus() != NULL\n");
138  CloseWindow(hwnd); // minimize
139  break;
140  case 4: // start tracing
141  ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
142  ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
143  ok(GetFocus() == NULL, "GetFocus() != NULL\n");
146  s_nWM_NCACTIVATE = 0;
148  s_nWM_ACTIVATE = 0;
149  s_bTracing = TRUE;
151  trace("SwitchToThisWindow(FALSE): tracing...\n");
152  break;
153  case 5: // tracing done
154  s_bTracing = FALSE;
155  trace("SwitchToThisWindow(FALSE): tracing done\n");
156  ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
157  ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
158  ok(GetFocus() == NULL, "GetFocus() != NULL\n");
159  ok(!s_nWM_SYSCOMMAND_SC_RESTORE, "WM_SYSCOMMAND SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_SC_RESTORE);
160  ok(!s_nWM_SYSCOMMAND_NOT_SC_RESTORE, "WM_SYSCOMMAND non-SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_NOT_SC_RESTORE);
161  ok(!s_nWM_NCACTIVATE, "WM_NCACTIVATE: %d\n", s_nWM_NCACTIVATE);
162  ok(!s_nWM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING: %d\n", s_nWM_WINDOWPOSCHANGING);
163  ok(!s_nWM_ACTIVATE, "WM_ACTIVATE: %d\n", s_nWM_ACTIVATE);
164  break;
165  default: // finish
167  return;
168  }
169  SetTimer(hwnd, id + 1, TIMER_INTERVAL, NULL);
170 }
171 
172 static LRESULT CALLBACK
174 {
175  DoMessage(hwnd, uMsg, wParam, lParam);
176  switch (uMsg)
177  {
178  case WM_CREATE:
180  break;
181  case WM_TIMER:
182  OnTimer(hwnd, (UINT)wParam);
183  break;
184  case WM_DESTROY:
185  PostQuitMessage(0);
186  break;
187  default:
188  return DefWindowProc(hwnd, uMsg, wParam, lParam);
189  }
190  return 0;
191 }
192 
194 {
195  WNDCLASSW wc;
196  HICON hIcon;
197  HCURSOR hCursor;
198  ATOM atom;
199  HWND hwnd;
200  MSG msg;
201 
203  ok(hIcon != NULL, "hIcon was NULL\n");
204  hCursor = LoadCursor(NULL, IDC_ARROW);
205  ok(hCursor != NULL, "hCursor was NULL\n");
206 
207  ZeroMemory(&wc, sizeof(wc));
208  wc.lpfnWndProc = WindowProc;
210  wc.hIcon = hIcon;
211  wc.hCursor = hCursor;
212  wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
214  atom = RegisterClassW(&wc);
215  ok(atom != 0, "RegisterClassW failed\n");
216 
217  if (!atom)
218  {
219  skip("atom is zero\n");
221  DestroyCursor(hCursor);
222  return;
223  }
224 
225  hwnd = CreateWindowW(s_szClassName, L"SwitchToThisWindow", WS_OVERLAPPEDWINDOW,
226  CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
228  ok(hwnd != NULL, "CreateWindowW failed\n");
229  trace("hwnd: %p\n", hwnd);
230 
231  if (!hwnd)
232  {
233  skip("hwnd is NULL\n");
236  DestroyCursor(hCursor);
237  return;
238  }
239 
242 
243  while (GetMessage(&msg, NULL, 0, 0))
244  {
247  }
248 
251  DestroyCursor(hCursor);
252 }
BOOL WINAPI CloseWindow(_In_ HWND)
#define DispatchMessage
Definition: winuser.h:5745
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
#define SC_RESTORE
Definition: winuser.h:2578
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
WORD ATOM
Definition: dimm.idl:113
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
#define TRUE
Definition: types.h:120
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:35
BOOL WINAPI UpdateWindow(_In_ HWND)
BOOL WINAPI InSendMessage(void)
Definition: message.c:1372
#define ZeroMemory
Definition: winbase.h:1667
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
static void OnTimer(HWND hwnd, UINT id)
HICON HCURSOR
Definition: windef.h:299
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI DestroyWindow(_In_ HWND)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4296
static BOOL s_bTracing
int32_t INT
Definition: typedefs.h:58
WPARAM wParam
Definition: combotst.c:138
static INT s_nWM_NCACTIVATE
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define L(x)
Definition: ntvdm.h:50
#define COLOR_3DFACE
Definition: winuser.h:923
#define FALSE
Definition: types.h:117
HWND WINAPI SetActiveWindow(_In_ HWND)
#define WM_NCACTIVATE
Definition: winuser.h:1675
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
static const char * DumpInSMEX(void)
WNDPROC lpfnWndProc
Definition: winuser.h:3157
#define CW_USEDEFAULT
Definition: winuser.h:225
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:656
LPCWSTR lpszClassName
Definition: winuser.h:3165
LONG_PTR LPARAM
Definition: windef.h:208
static INT s_nWM_ACTIVATE
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
static const WCHAR s_szClassName[]
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1596
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:2658
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define WM_TIMER
Definition: winuser.h:1729
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1648
DWORD WINAPI InSendMessageEx(LPVOID lpReserved)
Definition: message.c:1391
unsigned long DWORD
Definition: ntddk_ex.h:95
HICON hIcon
Definition: winuser.h:3161
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define LoadCursor
Definition: winuser.h:5792
#define TIMER_INTERVAL
HCURSOR hCursor
Definition: winuser.h:3162
#define SW_SHOWNORMAL
Definition: winuser.h:764
static void DoMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define WM_ACTIVATE
Definition: winuser.h:1599
HICON hIcon
Definition: msconfig.c:44
HBRUSH hbrBackground
Definition: winuser.h:3163
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
#define GetMessage
Definition: winuser.h:5770
HINSTANCE hInstance
Definition: winuser.h:3160
#define skip(...)
Definition: atltest.h:64
#define msg(x)
Definition: auth_time.c:54
HWND WINAPI GetFocus(void)
Definition: window.c:1894
#define IDC_ARROW
Definition: winuser.h:682
#define WM_CREATE
Definition: winuser.h:1595
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL WINAPI SetForegroundWindow(_In_ HWND)
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define LoadIcon
Definition: winuser.h:5793
LONG_PTR LRESULT
Definition: windef.h:209
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4022
static INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE
#define WM_SYSCOMMAND
Definition: winuser.h:1728
START_TEST(SwitchToThisWindow)
LPARAM lParam
Definition: combotst.c:139
static INT s_nWM_SYSCOMMAND_SC_RESTORE
static INT s_nWM_WINDOWPOSCHANGING
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
VOID WINAPI SwitchToThisWindow(HWND hwnd, BOOL fAltTab)
Definition: window.c:82
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)