ReactOS  0.4.14-dev-358-gbef841c
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 }
#define SC_RESTORE
Definition: winuser.h:2573
UINT uMsg
Definition: menu.cpp:213
BOOL WINAPI InSendMessage(void)
Definition: message.c:1371
static BOOL s_bTracing
WPARAM wParam
Definition: combotst.c:138
static INT s_nWM_NCACTIVATE
#define WM_NCACTIVATE
Definition: winuser.h:1670
long LONG
Definition: pedump.c:60
static const char * DumpInSMEX(void)
smooth NULL
Definition: ftsmooth.c:416
static INT s_nWM_ACTIVATE
#define trace
Definition: atltest.h:70
#define WM_TIMER
Definition: winuser.h:1724
#define WM_WINDOWPOSCHANGING
Definition: winuser.h:1643
DWORD WINAPI InSendMessageEx(LPVOID lpReserved)
Definition: message.c:1390
#define WM_ACTIVATE
Definition: winuser.h:1594
#define ok(value,...)
Definition: atltest.h:57
static INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE
#define WM_SYSCOMMAND
Definition: winuser.h:1723
LPARAM lParam
Definition: combotst.c:139
static INT s_nWM_SYSCOMMAND_SC_RESTORE
static INT s_nWM_WINDOWPOSCHANGING

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
smooth NULL
Definition: ftsmooth.c:416
DWORD WINAPI InSendMessageEx(LPVOID lpReserved)
Definition: message.c:1390
unsigned long DWORD
Definition: ntddk_ex.h:95
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388

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");
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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI CloseWindow(_In_ HWND)
#define TRUE
Definition: types.h:120
BOOL WINAPI DestroyWindow(_In_ HWND)
static BOOL s_bTracing
static INT s_nWM_NCACTIVATE
HWND WINAPI SetActiveWindow(_In_ HWND)
smooth NULL
Definition: ftsmooth.c:416
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:652
static INT s_nWM_ACTIVATE
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define trace
Definition: atltest.h:70
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define TIMER_INTERVAL
#define ok(value,...)
Definition: atltest.h:57
HWND WINAPI GetForegroundWindow(void)
Definition: ntwrapper.h:392
HWND WINAPI GetFocus(void)
Definition: window.c:1905
BOOL WINAPI SetForegroundWindow(_In_ HWND)
static INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE
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

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));
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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define DispatchMessage
Definition: winuser.h:5666
BOOL WINAPI TranslateMessage(_In_ const MSG *)
static HICON
Definition: imagelist.c:84
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
WORD ATOM
Definition: dimm.idl:113
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
BOOL WINAPI UpdateWindow(_In_ HWND)
#define ZeroMemory
Definition: winbase.h:1642
#define IDI_APPLICATION
Definition: winuser.h:699
HICON HCURSOR
Definition: windef.h:284
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define CreateWindowW(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4217
ATOM WINAPI RegisterClassW(_In_ CONST WNDCLASSW *)
#define COLOR_3DFACE
Definition: winuser.h:919
WNDPROC lpfnWndProc
Definition: winuser.h:3151
#define CW_USEDEFAULT
Definition: winuser.h:225
smooth NULL
Definition: ftsmooth.c:416
LPCWSTR lpszClassName
Definition: winuser.h:3159
static const WCHAR s_szClassName[]
BOOL WINAPI DestroyCursor(_In_ HCURSOR)
Definition: cursoricon.c:2654
#define trace
Definition: atltest.h:70
HICON hIcon
Definition: winuser.h:3155
static const WCHAR L[]
Definition: oid.c:1250
#define LoadCursor
Definition: winuser.h:5713
HCURSOR hCursor
Definition: winuser.h:3156
#define SW_SHOWNORMAL
Definition: winuser.h:764
HICON hIcon
Definition: msconfig.c:44
HBRUSH hbrBackground
Definition: winuser.h:3157
#define ok(value,...)
Definition: atltest.h:57
#define GetMessage
Definition: winuser.h:5691
HINSTANCE hInstance
Definition: winuser.h:3154
#define skip(...)
Definition: atltest.h:64
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define LoadIcon
Definition: winuser.h:5714

◆ WindowProc()

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

Definition at line 173 of file SwitchToThisWindow.c.

174 {
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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
UINT uMsg
Definition: menu.cpp:213
static void OnTimer(HWND hwnd, UINT id)
WPARAM wParam
Definition: combotst.c:138
smooth NULL
Definition: ftsmooth.c:416
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
#define WM_TIMER
Definition: winuser.h:1724
#define TIMER_INTERVAL
static void DoMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
unsigned int UINT
Definition: ndis.h:50
#define WM_CREATE
Definition: winuser.h:1590
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)

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().