ReactOS  0.4.14-dev-323-g6fe6a88
RegisterClassEx.c File Reference
#include "precomp.h"
Include dependency graph for RegisterClassEx.c:

Go to the source code of this file.

Functions

static ATOM _RegisterClass (LPCWSTR lpwszClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
 
static ATOM _GetClassAtom (LPCWSTR lpwszClassName, HINSTANCE hInstance)
 
static WNDPROC _GetWndproc (LPCWSTR lpwszClassName, HINSTANCE hInstance)
 
static ATOM _RegisterClassA (LPCSTR lpzClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
 
static ATOM _GetClassAtomA (LPCSTR lpszClassName, HINSTANCE hInstance)
 
static WNDPROC _GetWndprocA (LPCSTR lpszClassName, HINSTANCE hInstance)
 
HANDLE _CreateActCtxFromFile (LPCWSTR FileName)
 
VOID TestGlobalClasses (VOID)
 
VOID TestVersionedClasses (VOID)
 
 START_TEST (RegisterClassEx)
 

Function Documentation

◆ _CreateActCtxFromFile()

HANDLE _CreateActCtxFromFile ( LPCWSTR  FileName)

Definition at line 52 of file RegisterClassEx.c.

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 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:609
static const WCHAR separator[]
Definition: asmname.c:65
GLuint buffer
Definition: glext.h:5915
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
_In_ PCWSTR _Out_ PVOID * ActCtx
Definition: ldrtypes.h:247
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
static const WCHAR L[]
Definition: oid.c:1250
#define ok(value,...)
Definition: atltest.h:57
HANDLE WINAPI CreateActCtxW(PCACTCTXW pActCtx)
Definition: actctx.c:104

Referenced by TestVersionedClasses().

◆ _GetClassAtom()

static ATOM _GetClassAtom ( LPCWSTR  lpwszClassName,
HINSTANCE  hInstance 
)
static

Definition at line 18 of file RegisterClassEx.c.

19 {
20  WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW)};
21  return (ATOM)GetClassInfoExW(hInstance, lpwszClassName, &wcex);
22 }
BOOL WINAPI GetClassInfoExW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _Out_ LPWNDCLASSEXW)
WORD ATOM
Definition: dimm.idl:113
struct _WNDCLASSEXW WNDCLASSEXW
HINSTANCE hInstance
Definition: charmap.c:20

Referenced by TestGlobalClasses(), and TestVersionedClasses().

◆ _GetClassAtomA()

static ATOM _GetClassAtomA ( LPCSTR  lpszClassName,
HINSTANCE  hInstance 
)
static

Definition at line 39 of file RegisterClassEx.c.

40 {
41  WNDCLASSEXA wcex = {sizeof(WNDCLASSEX)};
42  return (ATOM)GetClassInfoExA(hInstance, lpszClassName, &wcex);
43 }
WORD ATOM
Definition: dimm.idl:113
HINSTANCE hInstance
Definition: charmap.c:20
BOOL WINAPI GetClassInfoExA(_In_opt_ HINSTANCE, _In_ LPCSTR, _Out_ LPWNDCLASSEXA)
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5620

Referenced by TestVersionedClasses().

◆ _GetWndproc()

static WNDPROC _GetWndproc ( LPCWSTR  lpwszClassName,
HINSTANCE  hInstance 
)
static

Definition at line 24 of file RegisterClassEx.c.

25 {
26  WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW)};
27  BOOL ret = GetClassInfoExW(hInstance, lpwszClassName, &wcex);
28  return ret ? wcex.lpfnWndProc : NULL;
29 }
BOOL WINAPI GetClassInfoExW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _Out_ LPWNDCLASSEXW)
struct _WNDCLASSEXW WNDCLASSEXW
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
int ret
WNDPROC lpfnWndProc
Definition: winuser.h:3192

Referenced by TestVersionedClasses().

◆ _GetWndprocA()

static WNDPROC _GetWndprocA ( LPCSTR  lpszClassName,
HINSTANCE  hInstance 
)
static

Definition at line 45 of file RegisterClassEx.c.

46 {
47  WNDCLASSEXA wcex = {sizeof(WNDCLASSEX)};
48  BOOL ret = GetClassInfoExA(hInstance, lpszClassName, &wcex);
49  return ret ? wcex.lpfnWndProc : NULL;
50 }
WNDPROC lpfnWndProc
Definition: winuser.h:3177
HINSTANCE hInstance
Definition: charmap.c:20
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
int ret
BOOL WINAPI GetClassInfoExA(_In_opt_ HINSTANCE, _In_ LPCSTR, _Out_ LPWNDCLASSEXA)
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5620

Referenced by TestVersionedClasses().

◆ _RegisterClass()

static ATOM _RegisterClass ( LPCWSTR  lpwszClassName,
HINSTANCE  hInstance,
UINT  style,
WNDPROC  lpfnWndProc 
)
static

Definition at line 10 of file RegisterClassEx.c.

11 {
12  WNDCLASSEXW wcex = {sizeof(WNDCLASSEXW), style, lpfnWndProc};
13  wcex.lpszClassName = lpwszClassName;
14  wcex.hInstance = hInstance;
15  return RegisterClassExW(&wcex);
16 }
struct _WNDCLASSEXW WNDCLASSEXW
ATOM WINAPI RegisterClassExW(_In_ CONST WNDCLASSEXW *)
HINSTANCE hInstance
Definition: charmap.c:20
LPCWSTR lpszClassName
Definition: winuser.h:3200
HINSTANCE hInstance
Definition: winuser.h:3195
Arabic default style
Definition: afstyles.h:93

Referenced by TestGlobalClasses(), and TestVersionedClasses().

◆ _RegisterClassA()

static ATOM _RegisterClassA ( LPCSTR  lpzClassName,
HINSTANCE  hInstance,
UINT  style,
WNDPROC  lpfnWndProc 
)
static

Definition at line 31 of file RegisterClassEx.c.

32 {
33  WNDCLASSEXA wcex = {sizeof(WNDCLASSEX), style, lpfnWndProc};
34  wcex.lpszClassName = lpzClassName;
35  wcex.hInstance = hInstance;
36  return RegisterClassExA(&wcex);
37 }
LPCSTR lpszClassName
Definition: winuser.h:3185
HINSTANCE hInstance
Definition: charmap.c:20
HINSTANCE hInstance
Definition: winuser.h:3180
ATOM WINAPI RegisterClassExA(_In_ CONST WNDCLASSEXA *)
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5620
Arabic default style
Definition: afstyles.h:93

Referenced by TestVersionedClasses().

◆ START_TEST()

START_TEST ( RegisterClassEx  )

Definition at line 278 of file RegisterClassEx.c.

279 {
282 }
VOID TestVersionedClasses(VOID)
VOID TestGlobalClasses(VOID)

◆ TestGlobalClasses()

VOID TestGlobalClasses ( VOID  )

Definition at line 67 of file RegisterClassEx.c.

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, "\n");
136  ok( b == 0, "\n");
137  ok( c != 0, "\n");
138  ok( d != 0, "\n");
139  ok( a == c, "\n");
140  ok( a == d, "\n"); /* In Windows 10 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 }
BOOL WINAPI UnregisterClassW(_In_ LPCWSTR, HINSTANCE)
WORD ATOM
Definition: dimm.idl:113
static ATOM _RegisterClass(LPCWSTR lpwszClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define a
Definition: ke_i.h:78
#define e
Definition: ke_i.h:82
smooth NULL
Definition: ftsmooth.c:416
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
#define CS_GLOBALCLASS
Definition: winuser.h:647
const GLubyte * c
Definition: glext.h:8905
static const WCHAR L[]
Definition: oid.c:1250
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
#define GetModuleHandle
Definition: winbase.h:3651
#define ok(value,...)
Definition: atltest.h:57
#define c
Definition: ke_i.h:80
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
static ATOM _GetClassAtom(LPCWSTR lpwszClassName, HINSTANCE hInstance)

Referenced by START_TEST().

◆ TestVersionedClasses()

VOID TestVersionedClasses ( VOID  )

Definition at line 159 of file RegisterClassEx.c.

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");
171  if (h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE)
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 }
BOOL WINAPI ActivateActCtx(IN HANDLE hActCtx, OUT PULONG_PTR ulCookie)
Definition: actctx.c:237
HANDLE _CreateActCtxFromFile(LPCWSTR FileName)
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
WORD ATOM
Definition: dimm.idl:113
static ATOM _RegisterClass(LPCWSTR lpwszClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
static ATOM _GetClassAtomA(LPCSTR lpszClassName, HINSTANCE hInstance)
static WNDPROC _GetWndprocA(LPCSTR lpszClassName, HINSTANCE hInstance)
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
GLuint buffer
Definition: glext.h:5915
static WNDPROC _GetWndproc(LPCWSTR lpwszClassName, HINSTANCE hInstance)
LRESULT WINAPI DefWindowProcW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
uint32_t ULONG_PTR
Definition: typedefs.h:63
BOOL WINAPI DeactivateActCtx(IN DWORD dwFlags, IN ULONG_PTR ulCookie)
Definition: actctx.c:268
#define a
Definition: ke_i.h:78
smooth NULL
Definition: ftsmooth.c:416
const char * LPCSTR
Definition: xmlstorage.h:183
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CS_GLOBALCLASS
Definition: winuser.h:647
#define swprintf(buf, format,...)
Definition: sprintf.c:56
const GLubyte * c
Definition: glext.h:8905
static const WCHAR L[]
Definition: oid.c:1250
LRESULT WINAPI DefWindowProcA(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
uint32_t DWORD_PTR
Definition: typedefs.h:63
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
LRESULT(CALLBACK * WNDPROC)(HWND, UINT, WPARAM, LPARAM)
Definition: winuser.h:2880
#define GetModuleHandle
Definition: winbase.h:3651
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define c
Definition: ke_i.h:80
static ATOM _RegisterClassA(LPCSTR lpzClassName, HINSTANCE hInstance, UINT style, WNDPROC lpfnWndProc)
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
static ATOM _GetClassAtom(LPCWSTR lpwszClassName, HINSTANCE hInstance)

Referenced by START_TEST().