ReactOS  0.4.14-dev-50-g13bb5e2
SetParent.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS API tests
3  * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4  * PURPOSE: Test for SetParent
5  * PROGRAMMERS: Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include "precomp.h"
9 
10 static HWND hWndList[5 + 1];
11 static const int hWndCount = sizeof(hWndList) / sizeof(hWndList[0]) - 1;
13 
14 #define ok_hwnd(val, exp) do \
15  { \
16  HWND _val = (val), _exp = (exp); \
17  int _ival = get_iwnd(_val, FALSE); \
18  int _iexp = get_iwnd(_exp, FALSE); \
19  ok(_val == _exp, #val " = %p (%d), expected %p (%d)\n", _val, _ival, _exp, _iexp); \
20  } while (0)
21 
22 static
23 int
25  _In_ HWND hWnd,
26  _In_ BOOL set)
27 {
28  int i;
29  if (!hWnd)
30  return 0;
31  for (i = 1; i <= hWndCount; i++)
32  {
33  if (hWndList[i] == hWnd)
34  return i;
35  }
36  if (!set)
37  return 0;
38  for (i = 1; i <= hWndCount; i++)
39  {
40  if (hWndList[i] == NULL)
41  {
42  hWndList[i] = hWnd;
43  return i;
44  }
45  }
46  ok(0, "Too many windows!\n");
47  return 0;
48 }
49 
50 static
51 BOOL
54  _In_ HWND hWnd,
56 {
57  HWND hLookingFor = (HWND)lParam;
58  return hWnd != hLookingFor;
59 }
60 
61 static
62 LRESULT
65  _In_ HWND hWnd,
69 {
70  HWND hTest;
71  int iwnd = get_iwnd(hWnd, TRUE);
72 
73  ok(GetCurrentThreadId() == dwThreadId, "Thread 0x%lx instead of 0x%lx\n", GetCurrentThreadId(), dwThreadId);
76 
78 
79  switch(message)
80  {
81  case WM_DESTROY:
82  if (GetParent(hWnd))
83  {
84  /* child window */
85  ok(EnumThreadWindows(dwThreadId, EnumProc, (LPARAM)hWnd), "Child window %p (%d) enumerated\n", hWnd, iwnd);
86  ok(!EnumChildWindows(GetParent(hWnd), EnumProc, (LPARAM)hWnd), "Child window %p (%d) not enumerated\n", hWnd, iwnd);
87  ok(!EnumThreadWindows(dwThreadId, EnumProc, (LPARAM)GetParent(hWnd)), "Parent window of %p (%d) not enumerated\n", hWnd, iwnd);
88  }
89  else
90  {
91  /* top-level window */
92  ok(!EnumThreadWindows(dwThreadId, EnumProc, (LPARAM)hWnd), "Window %p (%d) not enumerated in WM_DESTROY\n", hWnd, iwnd);
93  }
94  if (hWnd == hWndList[3])
95  {
96  hTest = SetParent(hWndList[4], hWndList[2]);
97  ok_hwnd(hTest, hWndList[1]);
98  hTest = SetParent(hWndList[5], hWndList[1]);
99  ok_hwnd(hTest, hWndList[2]);
100 
106  }
107  break;
108  }
109 
111 }
112 
113 
115 {
116  HWND hWnd;
117  MSG msg;
118 
119  SetCursorPos(0,0);
120 
123  RegisterSimpleClass(WndProc, L"CreateTest");
124 
125  hWnd = CreateWindowExW(0, L"CreateTest", NULL, 0, 10, 10, 20, 20, NULL, NULL, 0, NULL);
126  ok(hWnd != NULL, "CreateWindow failed\n");
127  ok(hWnd == hWndList[1], "Got %p, expected %p\n", hWnd, hWndList[1]);
128 
129  hWnd = CreateWindowExW(0, L"CreateTest", NULL, 0, 40, 10, 20, 20, NULL, NULL, 0, NULL);
130  ok(hWnd != NULL, "CreateWindow failed\n");
131  ok(hWnd == hWndList[2], "Got %p, expected %p\n", hWnd, hWndList[2]);
132 
133  hWnd = CreateWindowExW(0, L"CreateTest", NULL, WS_CHILD, 60, 10, 20, 20, hWndList[1], NULL, 0, NULL);
134  ok(hWnd != NULL, "CreateWindow failed\n");
135  ok(hWnd == hWndList[3], "Got %p, expected %p\n", hWnd, hWndList[3]);
136 
137  hWnd = CreateWindowExW(0, L"CreateTest", NULL, WS_CHILD, 80, 10, 20, 20, hWndList[1], NULL, 0, NULL);
138  ok(hWnd != NULL, "CreateWindow failed\n");
139  ok(hWnd == hWndList[4], "Got %p, expected %p\n", hWnd, hWndList[4]);
140 
141  hWnd = CreateWindowExW(0, L"CreateTest", NULL, WS_CHILD, 60, 10, 20, 20, hWndList[2], NULL, 0, NULL);
142  ok(hWnd != NULL, "CreateWindow failed\n");
143  ok(hWnd == hWndList[5], "Got %p, expected %p\n", hWnd, hWndList[5]);
144 
145 trace("\n");
146  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
147  {
148  int iwnd = get_iwnd(msg.hwnd, FALSE);
149  if(!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
150  RECORD_MESSAGE(iwnd, msg.message, POST, 0, 0);
151  DispatchMessageA( &msg );
152  }
153 trace("\n");
154  TRACE_CACHE();
155 trace("\n");
156 
162 
164  ok(!IsWindow(hWndList[1]), "\n");
165  ok( IsWindow(hWndList[2]), "\n");
166  ok(!IsWindow(hWndList[3]), "\n");
167  ok( IsWindow(hWndList[4]), "\n");
168  ok(!IsWindow(hWndList[5]), "\n");
169 
175 
176 trace("\n");
177  while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
178  {
179  int iwnd = get_iwnd(msg.hwnd, FALSE);
180  if(!(msg.message > WM_USER || IsDWmMsg(msg.message) || IseKeyMsg(msg.message)))
181  RECORD_MESSAGE(iwnd, msg.message, POST, 0, 0);
182  DispatchMessageA( &msg );
183  }
184 trace("\n");
185  TRACE_CACHE();
186  }
BOOL WINAPI EnumChildWindows(_In_opt_ HWND, _In_ WNDENUMPROC, _In_ LPARAM)
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
Definition: tftpd.h:59
#define PeekMessage
Definition: winuser.h:5731
#define TRUE
Definition: types.h:120
BOOL WINAPI IsWindow(_In_opt_ HWND)
HWND WINAPI SetParent(_In_ HWND, _In_opt_ HWND)
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
HANDLE HWND
Definition: compat.h:13
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
static HWND hWndList[5+1]
Definition: SetParent.c:10
BOOL WINAPI DestroyWindow(_In_ HWND)
WPARAM wParam
Definition: combotst.c:138
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static DWORD dwThreadId
Definition: SetParent.c:12
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ok_hwnd(val, exp)
Definition: SetParent.c:14
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
DWORD WINAPI GetCurrentThreadId(VOID)
Definition: thread.c:458
#define WM_DESTROY
Definition: winuser.h:1591
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
#define trace
Definition: atltest.h:70
BOOL WINAPI SetCursorPos(_In_ int, _In_ int)
Definition: cursoricon.c:2627
unsigned long DWORD
Definition: ntddk_ex.h:95
Definition: msgtrace.h:7
static const WCHAR L[]
Definition: oid.c:1250
HWND WINAPI CreateWindowExW(_In_ DWORD dwExStyle, _In_opt_ LPCWSTR lpClassName, _In_opt_ LPCWSTR lpWindowName, _In_ DWORD dwStyle, _In_ int X, _In_ int Y, _In_ int nWidth, _In_ int nHeight, _In_opt_ HWND hWndParent, _In_opt_ HMENU hMenu, _In_opt_ HINSTANCE hInstance, _In_opt_ LPVOID lpParam)
#define WM_USER
Definition: winuser.h:1877
#define _In_
Definition: no_sal2.h:204
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
HWND WINAPI GetParent(_In_ HWND)
START_TEST(SetParent)
Definition: SetParent.c:114
#define TRACE_CACHE()
Definition: msgtrace.h:58
static const int hWndCount
Definition: SetParent.c:11
#define ok(value,...)
Definition: atltest.h:57
unsigned int UINT
Definition: ndis.h:50
Definition: msgtrace.h:6
#define msg(x)
Definition: auth_time.c:54
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
static BOOL CALLBACK EnumProc(_In_ HWND hWnd, _In_ LPARAM lParam)
Definition: SetParent.c:53
#define PM_REMOVE
Definition: winuser.h:1182
static LRESULT CALLBACK WndProc(_In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: SetParent.c:64
LONG_PTR LRESULT
Definition: windef.h:209
Definition: _set.h:46
LPARAM lParam
Definition: combotst.c:139
static int get_iwnd(_In_ HWND hWnd, _In_ BOOL set)
Definition: SetParent.c:24