ReactOS 0.4.16-dev-197-g92996da
RegisterClassEx.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 RegisterClassEx
5 * PROGRAMMERS: Giannis Adamopoulos
6 */
7
8#include "precomp.h"
9
10static ATOM _RegisterClass(LPCWSTR lpwszClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
11{
12 WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW), style, lpfnWndProc};
13 wcex.lpszClassName = lpwszClassName;
14 wcex.hInstance = hInstance;
15 return RegisterClassExW(&wcex);
16}
17
19{
20 WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW)};
21 return (ATOM)GetClassInfoExW(hInstance, lpwszClassName, &wcex);
22}
23
25{
26 WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW)};
27 BOOL ret = GetClassInfoExW(hInstance, lpwszClassName, &wcex);
28 return ret ? wcex.lpfnWndProc : NULL;
29}
30
31static ATOM _RegisterClassA(LPCSTR lpzClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
32{
33 WNDCLASSEXA wcex = {sizeof(WNDCLASSEX), style, lpfnWndProc};
34 wcex.lpszClassName = lpzClassName;
35 wcex.hInstance = hInstance;
36 return RegisterClassExA(&wcex);
37}
38
40{
41 WNDCLASSEXA wcex = {sizeof(WNDCLASSEX)};
42 return (ATOM)GetClassInfoExA(hInstance, lpszClassName, &wcex);
43}
44
46{
47 WNDCLASSEXA wcex = {sizeof(WNDCLASSEX)};
48 BOOL ret = GetClassInfoExA(hInstance, lpszClassName, &wcex);
49 return ret ? wcex.lpfnWndProc : NULL;
50}
51
53{
54 ACTCTXW ActCtx = {sizeof(ACTCTX)};
56
57 ok (GetModuleFileNameW(NULL, buffer, MAX_PATH), "GetModuleFileName failed\n");
58 separator = wcsrchr(buffer, L'\\');
59 if (separator)
61
62 ActCtx.lpSource = buffer;
63
64 return CreateActCtxW(&ActCtx);
65}
66
68{
70 ATOM a,b,c,d,e;
71
72 a = _GetClassAtom(L"TestClass1", hmod);
73 b = _RegisterClass(L"TestClass1", hmod, 0, DefWindowProcW);
74 c = _GetClassAtom(L"TestClass1", hmod);
75 UnregisterClassW(L"TestClass1", hmod);
76 d = _GetClassAtom(L"TestClass1", hmod);
77 ok( a == 0, "\n");
78 ok( b != 0, "\n");
79 ok( c != 0, "\n");
80 ok( d == 0, "\n");
81 ok (b == c, "\n");
82
83 a = _GetClassAtom(L"TestClass2", hmod);
85 c = _GetClassAtom(L"TestClass2", hmod);
86 UnregisterClassW(L"TestClass2", hmod);
87 d = _GetClassAtom(L"TestClass2", hmod);
88 ok( a == 0, "\n");
89 ok( b != 0, "\n");
90 ok( c != 0, "\n");
91 ok( d == 0, "\n");
92 ok (b == c, "\n");
93
94 a = _RegisterClass(L"TestClass3", hmod, 0, DefWindowProcW);
95 b = _RegisterClass(L"TestClass3", hmod, 0, DefWindowProcW);
97 UnregisterClassW(L"TestClass3", hmod);
98 d = _GetClassAtom(L"TestClass3", hmod);
99 ok( a != 0, "\n");
100 ok( b == 0, "\n");
101 ok( c == 0, "\n");
102 ok( d == 0, "\n");
103
105 b = _RegisterClass(L"TestClass4", hmod, 0, DefWindowProcW);
106 c = _RegisterClass(L"TestClass4", hmod, 0, DefWindowProcW);
107 UnregisterClassW(L"TestClass4", hmod);
108 d = _GetClassAtom(L"TestClass4", hmod);
109 UnregisterClassW(L"TestClass4", hmod);
110 e = _GetClassAtom(L"TestClass4", hmod);
111 ok( a != 0, "\n");
112 ok( b != 0, "\n");
113 ok( c == 0, "\n");
114 ok( d != 0, "\n");
115 ok( e == 0, "\n");
116
117 a = _GetClassAtom(L"ComboBox", hmod);
118 b = _RegisterClass(L"ComboBox", hmod, 0, DefWindowProcW);
120 UnregisterClassW(L"ComboBox", hmod);
121 d = _GetClassAtom(L"ComboBox", hmod);
122 UnregisterClassW(L"TestClass4", hmod);
123 e = _GetClassAtom(L"TestClass4", hmod);
124 ok( a != 0, "\n");
125 ok( b != 0, "\n");
126 ok( c == 0, "\n");
127 ok( d != 0, "\n");
128 ok( e == 0, "\n");
129
130 a = _GetClassAtom(L"ScrollBar", hmod);
131 UnregisterClassW(L"ScrollBar", hmod);
132 b = _GetClassAtom(L"ScrollBar", hmod);
134 d = _GetClassAtom(L"ScrollBar", hmod);
135 ok( a != 0, "Wrong value for a. Expected != 0, got 0\n");
136 ok( b == 0, "Wrong value for b. Expected == 0, got %d\n", b);
137 //ok( c != 0, "Wrong value for c. Expected != 0, got 0\n");
138 //ok( d != 0, "Wrong value for d. Expected != 0, got 0\n");
139 //ok_int(a, c);
140 //ok_int(a, d); /* In Windows 10 and WHS testbot the last 4 tests fail */
141
142 a = _GetClassAtom(L"ListBox", (HMODULE)0xdead);
143 UnregisterClassW(L"ListBox", (HMODULE)0xdead);
144 b = _GetClassAtom(L"ListBox", (HMODULE)0xdead);
145 ok( a != 0, "\n");
146 ok( b == 0, "\n");
147
148 a = _RegisterClass(L"TestClass5", (HMODULE)0xdead, CS_GLOBALCLASS, DefWindowProcW);
149 b = _GetClassAtom(L"TestClass5", hmod);
150 UnregisterClassW(L"TestClass5", hmod);
151 c = _GetClassAtom(L"TestClass5", (HMODULE)0xdead);
152 d = _GetClassAtom(L"TestClass5", hmod);
153 ok( a != 0, "\n");
154 ok( b != 0, "\n");
155 ok( c == 0, "\n");
156 ok( d == 0, "\n");
157}
158
160{
162 HANDLE h1, h2;
163 ULONG_PTR cookie1, cookie2;
164 ATOM a,b,c,d;
165 WNDPROC proc1,proc2,proc3, proc4, proc5;
166 WCHAR buffer[50];
167
168
169 h1 = _CreateActCtxFromFile(L"verclasstest1.manifest");
170 h2 = _CreateActCtxFromFile(L"verclasstest2.manifest");
172 {
173 skip("Loading manifests failed. Skipping TestVersionedClasses\n");
174 return;
175 }
176
177 a = _RegisterClass(L"VersionTestClass1", hmod, 0, DefWindowProcA);
178 proc1 = _GetWndproc(L"VersionTestClass1", hmod);
179 b = _RegisterClass(L"VersionTestClass1", hmod, 0, DefWindowProcW);
180 ActivateActCtx(h1, &cookie1);
181 proc2 = _GetWndproc(L"VersionTestClass1", hmod);
182 c = _RegisterClass(L"VersionTestClass1", hmod, 0, DefWindowProcW);
183 d = _GetClassAtom(L"VersionTestClass1", hmod);
184 proc3 = _GetWndproc(L"VersionTestClass1", hmod);
185 proc4 = _GetWndproc((LPCWSTR)(DWORD_PTR)a, hmod);
186 DeactivateActCtx(0, cookie1);
187 proc5 = _GetWndproc(L"VersionTestClass1", hmod);
188 ok( a != 0, "\n");
189 ok( b == 0, "\n");
190 ok( c != 0, "\n");
191 ok( d != 0, "\n");
192 ok( a == c, "\n");
193 ok( a == d, "\n");
194 ok (proc1 == DefWindowProcA, "\n");
195 ok (proc2 == NULL, "Got 0x%p, expected NULL\n", proc2);
196 ok (proc3 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc3, DefWindowProcW);
197 ok (proc4 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc4, DefWindowProcW);
198 ok (proc5 == DefWindowProcA, "\n");
199
200 a = _GetClassAtom(L"Button", hmod);
202 proc1 = _GetWndproc(L"Button", (HMODULE)0xdead);
203 ActivateActCtx(h2, &cookie1);
205 proc2 = _GetWndproc(L"Button", (HMODULE)0xdead);
206 d = _GetClassAtom(L"3.3.3.3!Button", (HMODULE)0xdead);
207 proc3 = _GetWndproc(L"3.3.3.3!Button", (HMODULE)0xdead);
208 ok( a != 0, "\n");
209 ok( b == 0, "\n");
210 ok( c != 0, "\n");
211 ok( d != 0, "\n");
212 ok( a == c, "\n");
213 ok( d == a, "\n");
214 ok( proc1 != NULL, "\n");
215 ok( proc1 != DefWindowProcA, "Got 0x%p, expected not 0x%p\n", proc1, DefWindowProcA);
216 ok( proc2 == DefWindowProcA, "Got 0x%p, expected 0x%p\n", proc2, DefWindowProcA);
217 ok( proc3 == DefWindowProcA, "Got 0x%p, expected 0x%p\n", proc3, DefWindowProcA);
218
219 a = _RegisterClass(L"VersionTestClass2", hmod, CS_GLOBALCLASS, DefWindowProcW);
220 proc1 = _GetWndproc(L"VersionTestClass2", (HMODULE)0xdead);
221 b = _RegisterClass(L"VersionTestClass2", hmod, 0, DefWindowProcA);
222 proc2 = _GetWndproc(L"VersionTestClass2", hmod);
223 proc3 = _GetWndproc(L"VersionTestClass2", (HMODULE)0xdead);
224 ok (a != 0, "\n");
225 ok (b != 0, "\n");
226 ok (a == b, "\n");
227 ok (proc1 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc1, DefWindowProcW);
228 ok (proc2 == DefWindowProcA, "Got 0x%p, expected 0x%p\n", proc2, DefWindowProcA);
229 ok (proc3 == DefWindowProcW, "Got 0x%p, expected 0x%p\n", proc2, DefWindowProcA);
230
231 a = _RegisterClass(L"VersionTestClass3", hmod, 0, DefWindowProcW);
232 swprintf(buffer, L"#%d", a);
233 proc1 = _GetWndproc((LPCWSTR)(DWORD_PTR)a, hmod);
234 proc2 = _GetWndproc(buffer, hmod);
235 ok (a != 0, "\n");
236 ok (proc1 == DefWindowProcW, "\n");
237 ok (proc2 == 0, "Got 0x%p for %S, expected 0\n", proc2, buffer);
238 DeactivateActCtx(0, cookie1);
239
240 a = _RegisterClass(L"VersionTestClass3", hmod, 0, DefWindowProcW);
241 swprintf(buffer, L"#%d", a);
242 proc1 = _GetWndproc((LPCWSTR)(DWORD_PTR)a, hmod);
243 proc2 = _GetWndproc(buffer, hmod);
244 ok (a != 0, "\n");
245 ok (proc1 == DefWindowProcW, "\n");
246 ok (proc2 == 0, "Got 0x%p for %S, expected 0\n", proc2, buffer);
247
248 ActivateActCtx(h2, &cookie1);
249 a = _RegisterClassA("VersionTestClass7", hmod, 0, DefWindowProcW);
250 b = _GetClassAtomA("VersionTestClass7", hmod);
251 proc1 = _GetWndprocA("VersionTestClass7", hmod);
252 proc2 = _GetWndprocA((LPCSTR)(DWORD_PTR)a, hmod);
253 ok(a != 0, "\n");
254 ok(b != 0, "\n");
255 ok(a == b, "\n");
256 ok (proc1 == DefWindowProcW, "\n");
257 ok (proc2 == DefWindowProcW, "\n");
258
259 DeactivateActCtx(0, cookie1);
260
261 proc1 = _GetWndproc(L"Button", 0);
262 ActivateActCtx(h2, &cookie1);
263 ActivateActCtx(h1, &cookie2);
264 proc2 = _GetWndproc(L"Button", 0);
265 DeactivateActCtx(0, cookie2);
266 ActivateActCtx(0, &cookie2);
267 proc3 = _GetWndproc(L"Button", 0);
268 DeactivateActCtx(0, cookie2);
269 DeactivateActCtx(0, cookie1);
270 ok (proc1 != 0, "\n");
271 ok (proc2 != 0, "\n");
272 ok (proc4 != 0, "\n");
273 ok (proc1 == proc2, "\n");
274 ok (proc1 == proc3, "\n");
275
276}
277
279{
282}
static WNDPROC _GetWndprocA(LPCSTR lpszClassName, HINSTANCE hInstance)
VOID TestVersionedClasses(VOID)
static ATOM _GetClassAtom(LPCWSTR lpwszClassName, HINSTANCE hInstance)
static WNDPROC _GetWndproc(LPCWSTR lpwszClassName, HINSTANCE hInstance)
HANDLE _CreateActCtxFromFile(LPCWSTR FileName)
VOID TestGlobalClasses(VOID)
static ATOM _GetClassAtomA(LPCSTR lpszClassName, HINSTANCE hInstance)
static ATOM _RegisterClassA(LPCSTR lpzClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
static ATOM _RegisterClass(LPCWSTR lpwszClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
Arabic default style
Definition: afstyles.h:94
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
HINSTANCE hInstance
Definition: charmap.c:19
WORD ATOM
Definition: dimm.idl:113
#define NULL
Definition: types.h:112
#define wcsrchr
Definition: compat.h:16
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
static const WCHAR separator[]
Definition: asmname.c:65
BOOL WINAPI DeactivateActCtx(IN DWORD dwFlags, IN ULONG_PTR ulCookie)
Definition: actctx.c:268
BOOL WINAPI ActivateActCtx(IN HANDLE hActCtx, OUT PULONG_PTR ulCookie)
Definition: actctx.c:237
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx)
Definition: actctx.c:102
#define swprintf
Definition: precomp.h:40
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
#define e
Definition: ke_i.h:82
#define a
Definition: ke_i.h:78
#define c
Definition: ke_i.h:80
#define b
Definition: ke_i.h:79
_In_ PCWSTR _Out_ PVOID * ActCtx
Definition: ldrtypes.h:247
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:143
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
HINSTANCE hInstance
Definition: winuser.h:3209
WNDPROC lpfnWndProc
Definition: winuser.h:3206
LPCSTR lpszClassName
Definition: winuser.h:3214
LPCWSTR lpszClassName
Definition: winuser.h:3229
WNDPROC lpfnWndProc
Definition: winuser.h:3221
HINSTANCE hInstance
Definition: winuser.h:3224
uint32_t DWORD_PTR
Definition: typedefs.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
int ret
#define GetModuleHandle
Definition: winbase.h:3851
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI GetClassInfoExA(_In_opt_ HINSTANCE, _In_ LPCSTR, _Out_ LPWNDCLASSEXA)
BOOL WINAPI GetClassInfoExW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _Out_ LPWNDCLASSEXW)
#define RegisterClassEx
Definition: winuser.h:5849
ATOM WINAPI RegisterClassExA(_In_ CONST WNDCLASSEXA *)
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5731
#define CS_GLOBALCLASS
Definition: winuser.h:652
struct _WNDCLASSEXW WNDCLASSEXW
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2909
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185