ReactOS 0.4.15-dev-7704-gc07eb9f
SwitchToThisWindow.c File Reference
#include "precomp.h"
Include dependency graph for SwitchToThisWindow.c:

Go to the source code of this file.

Macros

#define TIMER_INTERVAL   200
 

Functions

static const charDumpInSMEX (void)
 
static void DoMessage (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static void OnTimer (HWND hwnd, UINT id)
 
static LRESULT CALLBACK WindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
 START_TEST (SwitchToThisWindow)
 

Variables

static const WCHAR s_szClassName [] = L"SwitchTest"
 
static BOOL s_bTracing = FALSE
 
static INT s_nWM_SYSCOMMAND_SC_RESTORE = 0
 
static INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE = 0
 
static INT s_nWM_NCACTIVATE = 0
 
static INT s_nWM_WINDOWPOSCHANGING = 0
 
static INT s_nWM_ACTIVATE = 0
 

Macro Definition Documentation

◆ TIMER_INTERVAL

#define TIMER_INTERVAL   200

Definition at line 20 of file SwitchToThisWindow.c.

Function Documentation

◆ DoMessage()

static void DoMessage ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 45 of file SwitchToThisWindow.c.

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}
static BOOL s_bTracing
static INT s_nWM_ACTIVATE
static INT s_nWM_SYSCOMMAND_SC_RESTORE
static const char * DumpInSMEX(void)
static INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE
static INT s_nWM_NCACTIVATE
static INT s_nWM_WINDOWPOSCHANGING
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
long LONG
Definition: pedump.c:60
DWORD WINAPI InSendMessageEx(LPVOID lpReserved)
Definition: message.c:1391
#define WM_SYSCOMMAND
Definition: winuser.h:1740
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1660
#define WM_ACTIVATE
Definition: winuser.h:1611
#define WM_NCACTIVATE
Definition: winuser.h:1687
BOOL WINAPI InSendMessage(void)
Definition: message.c:1372
#define WM_TIMER
Definition: winuser.h:1741
#define SC_RESTORE
Definition: winuser.h:2597

Referenced by WindowProc().

◆ DumpInSMEX()

static const char * DumpInSMEX ( void  )
static

Definition at line 23 of file SwitchToThisWindow.c.

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}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned long DWORD
Definition: ntddk_ex.h:95

Referenced by DoMessage().

◆ OnTimer()

static void OnTimer ( HWND  hwnd,
UINT  id 
)
static

Definition at line 88 of file SwitchToThisWindow.c.

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}
#define TIMER_INTERVAL
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
VOID WINAPI SwitchToThisWindow(HWND hwnd, BOOL fAltTab)
Definition: window.c:82
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
HWND WINAPI GetFocus(void)
Definition: window.c:1893
HWND WINAPI GetActiveWindow(void)
Definition: winpos.c:138
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
BOOL WINAPI SetForegroundWindow(_In_ HWND)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:656
HWND WINAPI SetActiveWindow(_In_ HWND)
BOOL WINAPI CloseWindow(_In_ HWND)
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
BOOL WINAPI DestroyWindow(_In_ HWND)

Referenced by WindowProc().

◆ START_TEST()

START_TEST ( SwitchToThisWindow  )

Definition at line 193 of file SwitchToThisWindow.c.

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 const WCHAR s_szClassName[]
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define skip(...)
Definition: atltest.h:64
#define msg(x)
Definition: auth_time.c:54
WORD ATOM
Definition: dimm.idl:113
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
static HICON
Definition: imagelist.c:84
HICON hIcon
Definition: msconfig.c:44
#define L(x)
Definition: ntvdm.h:50
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
LPCWSTR lpszClassName
Definition: winuser.h:3184
HBRUSH hbrBackground
Definition: winuser.h:3182
HICON hIcon
Definition: winuser.h:3180
HINSTANCE hInstance
Definition: winuser.h:3179
WNDPROC lpfnWndProc
Definition: winuser.h:3176
HCURSOR hCursor
Definition: winuser.h:3181
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
#define ZeroMemory
Definition: winbase.h:1712
HICON HCURSOR
Definition: windef.h:299
#define SW_SHOWNORMAL
Definition: winuser.h:769
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:2672
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define IDC_ARROW
Definition: winuser.h:687
#define IDI_APPLICATION
Definition: winuser.h:704
#define GetMessage
Definition: winuser.h:5789
#define LoadIcon
Definition: winuser.h:5812
BOOL WINAPI UpdateWindow(_In_ HWND)
#define LoadCursor
Definition: winuser.h:5811
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4315
#define CW_USEDEFAULT
Definition: winuser.h:225
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
#define DispatchMessage
Definition: winuser.h:5764
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2036
#define COLOR_3DFACE
Definition: winuser.h:928

◆ WindowProc()

static LRESULT CALLBACK WindowProc ( HWND  hwnd,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 173 of file SwitchToThisWindow.c.

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}
static void OnTimer(HWND hwnd, UINT id)
static void DoMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
unsigned int UINT
Definition: ndis.h:50
#define DefWindowProc
Definition: ros2win.h:31
#define WM_CREATE
Definition: winuser.h:1607
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define WM_DESTROY
Definition: winuser.h:1608

Referenced by START_TEST().

Variable Documentation

◆ s_bTracing

BOOL s_bTracing = FALSE
static

Definition at line 12 of file SwitchToThisWindow.c.

Referenced by DoMessage(), and OnTimer().

◆ s_nWM_ACTIVATE

INT s_nWM_ACTIVATE = 0
static

Definition at line 18 of file SwitchToThisWindow.c.

Referenced by DoMessage(), and OnTimer().

◆ s_nWM_NCACTIVATE

INT s_nWM_NCACTIVATE = 0
static

Definition at line 16 of file SwitchToThisWindow.c.

Referenced by DoMessage(), and OnTimer().

◆ s_nWM_SYSCOMMAND_NOT_SC_RESTORE

INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE = 0
static

Definition at line 15 of file SwitchToThisWindow.c.

Referenced by DoMessage(), and OnTimer().

◆ s_nWM_SYSCOMMAND_SC_RESTORE

INT s_nWM_SYSCOMMAND_SC_RESTORE = 0
static

Definition at line 14 of file SwitchToThisWindow.c.

Referenced by DoMessage(), and OnTimer().

◆ s_nWM_WINDOWPOSCHANGING

INT s_nWM_WINDOWPOSCHANGING = 0
static

Definition at line 17 of file SwitchToThisWindow.c.

Referenced by DoMessage(), and OnTimer().

◆ s_szClassName

const WCHAR s_szClassName[] = L"SwitchTest"
static

Definition at line 10 of file SwitchToThisWindow.c.

Referenced by START_TEST().