ReactOS 0.4.15-dev-7968-g24a56f8
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
10static HWND hWndList[5 + 1];
11static 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
22static
23int
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
50static
51BOOL
56{
57 HWND hLookingFor = (HWND)lParam;
58 return hWnd != hLookingFor;
59}
60
61static
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
145trace("\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);
152 }
153trace("\n");
154 TRACE_CACHE();
155trace("\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
176trace("\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);
183 }
184trace("\n");
185 TRACE_CACHE();
186 }
static LRESULT CALLBACK WndProc(_In_ HWND hWnd, _In_ UINT message, _In_ WPARAM wParam, _In_ LPARAM lParam)
Definition: SetParent.c:64
static DWORD dwThreadId
Definition: SetParent.c:12
static HWND hWndList[5+1]
Definition: SetParent.c:10
static const int hWndCount
Definition: SetParent.c:11
static BOOL CALLBACK EnumProc(_In_ HWND hWnd, _In_ LPARAM lParam)
Definition: SetParent.c:53
#define ok_hwnd(val, exp)
Definition: SetParent.c:14
static int get_iwnd(_In_ HWND hWnd, _In_ BOOL set)
Definition: SetParent.c:24
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
Definition: _set.h:50
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HANDLE HWND
Definition: compat.h:19
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CALLBACK
Definition: compat.h:35
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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
#define _In_
Definition: ms_sal.h:308
static BOOL IsDWmMsg(UINT msg)
Definition: msgtrace.h:39
#define RECORD_MESSAGE(...)
Definition: msgtrace.h:60
#define TRACE_CACHE()
Definition: msgtrace.h:58
@ POST
Definition: msgtrace.h:7
@ SENT
Definition: msgtrace.h:6
static BOOL IseKeyMsg(UINT msg)
Definition: msgtrace.h:52
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_CHILD
Definition: pedump.c:617
Definition: tftpd.h:60
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
static __inline ATOM RegisterSimpleClass(WNDPROC lpfnWndProc, LPCWSTR lpszClassName)
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
LRESULT WINAPI DispatchMessageA(_In_ const MSG *)
BOOL WINAPI IsWindow(_In_opt_ HWND)
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HWND WINAPI SetParent(_In_ HWND, _In_opt_ HWND)
BOOL WINAPI SetCursorPos(_In_ int, _In_ int)
Definition: cursoricon.c:2693
BOOL WINAPI EnumChildWindows(_In_opt_ HWND, _In_ WNDENUMPROC, _In_ LPARAM)
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 PM_REMOVE
Definition: winuser.h:1196
#define PeekMessage
Definition: winuser.h:5830
HWND WINAPI GetParent(_In_ HWND)
#define WM_USER
Definition: winuser.h:1895
#define WM_DESTROY
Definition: winuser.h:1609
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)
BOOL WINAPI DestroyWindow(_In_ HWND)