ReactOS 0.4.15-dev-8135-g1bc6c90
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
10static const WCHAR s_szClassName[] = L"SwitchTest";
11
13
19
20#define TIMER_INTERVAL 200
21
22static 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
44static 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
87static 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");
112 s_nWM_ACTIVATE = 0;
115 trace("SwitchToThisWindow(TRUE): tracing...\n");
116 break;
117 case 2: // tracing done
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");
148 s_nWM_ACTIVATE = 0;
151 trace("SwitchToThisWindow(FALSE): tracing...\n");
152 break;
153 case 5: // tracing done
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
172static LRESULT CALLBACK
174{
175 DoMessage(hwnd, uMsg, wParam, lParam);
176 switch (uMsg)
177 {
178 case WM_CREATE:
180 break;
181 case WM_TIMER:
183 break;
184 case WM_DESTROY:
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));
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}
static BOOL s_bTracing
static const WCHAR s_szClassName[]
static INT s_nWM_ACTIVATE
#define TIMER_INTERVAL
static void OnTimer(HWND hwnd, UINT id)
static void DoMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
static INT s_nWM_SYSCOMMAND_SC_RESTORE
static const char * DumpInSMEX(void)
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
static INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE
static INT s_nWM_NCACTIVATE
static INT s_nWM_WINDOWPOSCHANGING
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#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
unsigned long DWORD
Definition: ntddk_ex.h:95
static HICON
Definition: imagelist.c:84
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:3185
HBRUSH hbrBackground
Definition: winuser.h:3183
HICON hIcon
Definition: winuser.h:3181
HINSTANCE hInstance
Definition: winuser.h:3180
WNDPROC lpfnWndProc
Definition: winuser.h:3177
HCURSOR hCursor
Definition: winuser.h:3182
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
DWORD WINAPI InSendMessageEx(LPVOID lpReserved)
Definition: message.c:1391
VOID WINAPI SwitchToThisWindow(HWND hwnd, BOOL fAltTab)
Definition: window.c:82
#define ZeroMemory
Definition: winbase.h:1712
_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:770
HWND WINAPI GetFocus(void)
Definition: window.c:1893
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
#define WM_SYSCOMMAND
Definition: winuser.h:1741
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:2720
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:1661
#define WM_CREATE
Definition: winuser.h:1608
__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:1612
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:656
#define GetMessage
Definition: winuser.h:5790
#define WM_NCACTIVATE
Definition: winuser.h:1688
BOOL WINAPI InSendMessage(void)
Definition: message.c:1372
HWND WINAPI SetActiveWindow(_In_ HWND)
#define WM_TIMER
Definition: winuser.h:1742
#define LoadIcon
Definition: winuser.h:5813
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5812
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4316
#define CW_USEDEFAULT
Definition: winuser.h:225
#define WM_DESTROY
Definition: winuser.h:1609
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
BOOL WINAPI CloseWindow(_In_ HWND)
#define DispatchMessage
Definition: winuser.h:5765
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define SC_RESTORE
Definition: winuser.h:2598
BOOL WINAPI DestroyWindow(_In_ HWND)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2084
#define COLOR_3DFACE
Definition: winuser.h:929
__wchar_t WCHAR
Definition: xmlstorage.h:180