wnaspi32: Make winaspi.dll into a stand-alone 16-bit module.
[wine] / dlls / user32 / tests / class.c
1 /* Unit test suite for window classes.
2  *
3  * Copyright 2002 Mike McCormack
4  * Copyright 2003 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 /* To get CS_DROPSHADOW with the MSVC headers */
22 #define _WIN32_WINNT 0x0501
23
24 #include <assert.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28
29 #include "wine/test.h"
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winreg.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35
36 /* we don't want to include commctrl.h: */
37 static const CHAR WC_EDITA[] = "Edit";
38 static const WCHAR WC_EDITW[] = {'E','d','i','t',0};
39
40 #define NUMCLASSWORDS 4
41
42 #define IS_WNDPROC_HANDLE(x) (((ULONG_PTR)(x) >> 16) == (~0u >> 16))
43
44 static LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
45 {
46     return DefWindowProcW (hWnd, msg, wParam, lParam);
47 }
48
49 static LRESULT WINAPI ClassTest_WndProc2 (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
50 {
51     return DefWindowProcA (hWnd, msg, wParam, lParam);
52 }
53
54 /***********************************************************************
55  */
56 static void ClassTest(HINSTANCE hInstance, BOOL global)
57 {
58     WNDCLASSW cls, wc;
59     static const WCHAR className[] = {'T','e','s','t','C','l','a','s','s',0};
60     static const WCHAR winName[]   = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
61     ATOM test_atom;
62     HWND hTestWnd;
63     LONG i;
64     WCHAR str[20];
65     ATOM classatom;
66
67     cls.style         = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
68     cls.lpfnWndProc   = ClassTest_WndProc;
69     cls.cbClsExtra    = NUMCLASSWORDS*sizeof(DWORD);
70     cls.cbWndExtra    = 12;
71     cls.hInstance     = hInstance;
72     cls.hIcon         = LoadIconW (0, (LPWSTR)IDI_APPLICATION);
73     cls.hCursor       = LoadCursorW (0, (LPWSTR)IDC_ARROW);
74     cls.hbrBackground = GetStockObject (WHITE_BRUSH);
75     cls.lpszMenuName  = 0;
76     cls.lpszClassName = className;
77
78     classatom=RegisterClassW(&cls);
79     if (!classatom && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
80         return;
81     ok(classatom, "failed to register class\n");
82
83     ok(!RegisterClassW (&cls),
84         "RegisterClass of the same class should fail for the second time\n");
85
86     /* Setup windows */
87     hTestWnd = CreateWindowW (className, winName,
88        WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
89        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
90        0, hInstance, 0);
91
92     ok(hTestWnd!=0, "Failed to create window\n");
93
94     /* test initial values of valid classwords */
95     for(i=0; i<NUMCLASSWORDS; i++)
96     {
97         SetLastError(0);
98         ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
99             "GetClassLongW initial value nonzero!\n");
100         ok(!GetLastError(),
101             "GetClassLongW failed!\n");
102     }
103
104     if (0)
105     {
106     /*
107      *  GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
108      *  does not fail on Win 98, though MSDN says it should
109      */
110     SetLastError(0);
111     GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
112     ok(GetLastError(),
113         "GetClassLongW() with invalid offset did not fail\n");
114     }
115
116     /* set values of valid class words */
117     for(i=0; i<NUMCLASSWORDS; i++)
118     {
119         SetLastError(0);
120         ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
121             "GetClassLongW(%d) initial value nonzero!\n",i);
122         ok(!GetLastError(),
123             "SetClassLongW(%d) failed!\n",i);
124     }
125
126     /* test values of valid classwords that we set */
127     for(i=0; i<NUMCLASSWORDS; i++)
128     {
129         SetLastError(0);
130         ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
131             "GetClassLongW value doesn't match what was set!\n");
132         ok(!GetLastError(),
133             "GetClassLongW failed!\n");
134     }
135
136     /* check GetClassName */
137     i = GetClassNameW(hTestWnd, str, sizeof(str)/sizeof(str[0]));
138     ok(i == lstrlenW(className),
139         "GetClassName returned incorrect length\n");
140     ok(!lstrcmpW(className,str),
141         "GetClassName returned incorrect name for this window's class\n");
142
143     /* check GetClassInfo with our hInstance */
144     if((test_atom = GetClassInfoW(hInstance, str, &wc)))
145     {
146         ok(test_atom == classatom,
147             "class atom did not match\n");
148         ok(wc.cbClsExtra == cls.cbClsExtra,
149             "cbClsExtra did not match\n");
150         ok(wc.cbWndExtra == cls.cbWndExtra,
151             "cbWndExtra did not match\n");
152         ok(wc.hbrBackground == cls.hbrBackground,
153             "hbrBackground did not match\n");
154         ok(wc.hCursor== cls.hCursor,
155             "hCursor did not match\n");
156         ok(wc.hInstance== cls.hInstance,
157             "hInstance did not match\n");
158     }
159     else
160         ok(FALSE,"GetClassInfo (hinstance) failed!\n");
161
162     /* check GetClassInfo with zero hInstance */
163     if(global)
164     {
165         if((test_atom = GetClassInfoW(0, str, &wc)))
166         {
167             ok(test_atom == classatom,
168                 "class atom did not match %x != %x\n", test_atom, classatom);
169             ok(wc.cbClsExtra == cls.cbClsExtra,
170                 "cbClsExtra did not match %x!=%x\n",wc.cbClsExtra,cls.cbClsExtra);
171             ok(wc.cbWndExtra == cls.cbWndExtra,
172                 "cbWndExtra did not match %x!=%x\n",wc.cbWndExtra,cls.cbWndExtra);
173             ok(wc.hbrBackground == cls.hbrBackground,
174                 "hbrBackground did not match %p!=%p\n",wc.hbrBackground,cls.hbrBackground);
175             ok(wc.hCursor== cls.hCursor,
176                 "hCursor did not match %p!=%p\n",wc.hCursor,cls.hCursor);
177             ok(!wc.hInstance,
178                 "hInstance not zero for global class %p\n",wc.hInstance);
179         }
180         else
181             ok(FALSE,"GetClassInfo (0) failed for global class!\n");
182     }
183     else
184     {
185         ok(!GetClassInfoW(0, str, &wc),
186             "GetClassInfo (0) succeeded for local class!\n");
187     }
188
189     ok(!UnregisterClassW(className, hInstance),
190         "Unregister class succeeded with window existing\n");
191
192     ok(DestroyWindow(hTestWnd),
193         "DestroyWindow() failed!\n");
194
195     ok(UnregisterClassW(className, hInstance),
196         "UnregisterClass() failed\n");
197
198     return;
199 }
200
201 static void check_style( const char *name, int must_exist, UINT style, UINT ignore )
202 {
203     WNDCLASS wc;
204
205     if (GetClassInfo( 0, name, &wc ))
206     {
207         ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n",
208             name, ~wc.style & style, wc.style, style );
209         ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n",
210             name, wc.style & ~style, wc.style, style );
211     }
212     else
213         ok( !must_exist, "System class %s does not exist\n", name );
214 }
215
216 /* test styles of system classes */
217 static void test_styles(void)
218 {
219     /* check style bits */
220     check_style( "Button",     1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
221     check_style( "ComboBox",   1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
222     check_style( "Edit",       1, CS_PARENTDC | CS_DBLCLKS, 0 );
223     check_style( "ListBox",    1, CS_PARENTDC | CS_DBLCLKS, CS_PARENTDC /*FIXME*/ );
224     check_style( "MDIClient",  1, 0, 0 );
225     check_style( "ScrollBar",  1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
226     check_style( "Static",     1, CS_PARENTDC | CS_DBLCLKS, 0 );
227     check_style( "ComboLBox",  1, CS_SAVEBITS | CS_DBLCLKS, 0 );
228     check_style( "DDEMLEvent", 0, 0, 0 );
229     check_style( "Message",    0, 0, 0 );
230     check_style( "#32768",     1, CS_DROPSHADOW | CS_SAVEBITS | CS_DBLCLKS, CS_DROPSHADOW );  /* menu */
231     check_style( "#32769",     1, CS_DBLCLKS, 0 );  /* desktop */
232     check_style( "#32770",     1, CS_SAVEBITS | CS_DBLCLKS, 0 );  /* dialog */
233     todo_wine { check_style( "#32771",     1, CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW, 0 ); } /* task switch */
234     check_style( "#32772",     1, 0, 0 );  /* icon title */
235 }
236
237 static void check_class_(int line, HINSTANCE inst, const char *name, const char *menu_name)
238 {
239     WNDCLASS wc;
240     UINT atom = GetClassInfo(inst,name,&wc);
241     ok_(__FILE__,line)( atom, "Class %s %p not found\n", name, inst );
242     if (atom)
243     {
244         if (wc.lpszMenuName && menu_name)
245             ok_(__FILE__,line)( !strcmp( menu_name, wc.lpszMenuName ),
246                                 "Wrong name %s/%s for class %s %p\n",
247                                 wc.lpszMenuName, menu_name, name, inst );
248         else
249             ok_(__FILE__,line)( !menu_name == !wc.lpszMenuName, "Wrong name %p/%p for class %s %p\n",
250                                 wc.lpszMenuName, menu_name, name, inst );
251     }
252 }
253 #define check_class(inst,name,menu) check_class_(__LINE__,inst,name,menu)
254
255 static void check_instance_( int line, const char *name, HINSTANCE inst,
256                              HINSTANCE info_inst, HINSTANCE gcl_inst )
257 {
258     WNDCLASSA wc;
259     HWND hwnd;
260
261     ok_(__FILE__,line)( GetClassInfo( inst, name, &wc ), "Couldn't find class %s inst %p\n", name, inst );
262     ok_(__FILE__,line)( wc.hInstance == info_inst, "Wrong info instance %p/%p for class %s\n",
263                         wc.hInstance, info_inst, name );
264     hwnd = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, inst, 0 );
265     ok_(__FILE__,line)( hwnd != NULL, "Couldn't create window for class %s inst %p\n", name, inst );
266     ok_(__FILE__,line)( (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ) == gcl_inst,
267                         "Wrong GCL instance %p/%p for class %s\n",
268         (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ), gcl_inst, name );
269     ok_(__FILE__,line)( (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ) == inst,
270                         "Wrong GWL instance %p/%p for window %s\n",
271         (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), inst, name );
272     ok_(__FILE__,line)(!UnregisterClassA(name, inst),
273                        "UnregisterClassA should fail while exists a class window\n");
274     ok_(__FILE__,line)(GetLastError() == ERROR_CLASS_HAS_WINDOWS,
275                        "GetLastError() should be set to ERROR_CLASS_HAS_WINDOWS not %d\n", GetLastError());
276     DestroyWindow(hwnd);
277 }
278 #define check_instance(name,inst,info_inst,gcl_inst) check_instance_(__LINE__,name,inst,info_inst,gcl_inst)
279
280 struct class_info
281 {
282     const char *name;
283     HINSTANCE inst, info_inst, gcl_inst;
284 };
285
286 static DWORD WINAPI thread_proc(void *param)
287 {
288     struct class_info *class_info = param;
289
290     check_instance(class_info->name, class_info->inst, class_info->info_inst, class_info->gcl_inst);
291
292     return 0;
293 }
294
295 static void check_thread_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
296 {
297     HANDLE hThread;
298     DWORD tid;
299     struct class_info class_info;
300
301     class_info.name = name;
302     class_info.inst = inst;
303     class_info.info_inst = info_inst;
304     class_info.gcl_inst = gcl_inst;
305
306     hThread = CreateThread(NULL, 0, thread_proc, &class_info, 0, &tid);
307     ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
308     ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
309     CloseHandle(hThread);
310 }
311
312 /* test various instance parameters */
313 static void test_instances(void)
314 {
315     WNDCLASSA cls, wc;
316     HWND hwnd, hwnd2;
317     const char *name = "__test__";
318     HINSTANCE kernel32 = GetModuleHandleA("kernel32");
319     HINSTANCE user32 = GetModuleHandleA("user32");
320     HINSTANCE main_module = GetModuleHandleA(NULL);
321     DWORD r;
322     char buffer[0x10];
323
324     memset( &cls, 0, sizeof(cls) );
325     cls.style         = CS_HREDRAW | CS_VREDRAW;
326     cls.lpfnWndProc   = ClassTest_WndProc;
327     cls.cbClsExtra    = 0;
328     cls.cbWndExtra    = 0;
329     cls.lpszClassName = name;
330
331     cls.lpszMenuName  = "main_module";
332     cls.hInstance = main_module;
333
334     ok( RegisterClassA( &cls ), "Failed to register local class for main module\n" );
335     check_class( main_module, name, "main_module" );
336     check_instance( name, main_module, main_module, main_module );
337     check_thread_instance( name, main_module, main_module, main_module );
338
339     cls.lpszMenuName  = "kernel32";
340     cls.hInstance = kernel32;
341     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
342     check_class( kernel32, name, "kernel32" );
343     check_class( main_module, name, "main_module" );
344     check_instance( name, kernel32, kernel32, kernel32 );
345     check_thread_instance( name, kernel32, kernel32, kernel32 );
346     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
347
348     /* Bug 2631 - Supplying an invalid number of bytes fails */
349     cls.cbClsExtra    = 0;
350     cls.cbWndExtra    = -1;
351     SetLastError(0xdeadbeef);
352     ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
353           "Failed with invalid number of WndExtra bytes\n");
354
355     cls.cbClsExtra    = -1;
356     cls.cbWndExtra    = 0;
357     SetLastError(0xdeadbeef);
358     ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
359           "Failed with invalid number of ClsExtra bytes\n");
360
361     cls.cbClsExtra    = -1;
362     cls.cbWndExtra    = -1;
363     SetLastError(0xdeadbeef);
364     ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
365           "Failed with invalid number of ClsExtra and cbWndExtra bytes\n");
366
367     cls.cbClsExtra    = 0;
368     cls.cbWndExtra    = 0;
369     SetLastError(0xdeadbeef);
370
371     /* setting global flag doesn't change status of class */
372     hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
373     SetClassLongA( hwnd, GCL_STYLE, CS_GLOBALCLASS );
374     cls.lpszMenuName  = "kernel32";
375     cls.hInstance = kernel32;
376     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
377     check_class( kernel32, name, "kernel32" );
378     check_class( main_module, name, "main_module" );
379     check_instance( name, kernel32, kernel32, kernel32 );
380     check_instance( name, main_module, main_module, main_module );
381     check_thread_instance( name, kernel32, kernel32, kernel32 );
382     check_thread_instance( name, main_module, main_module, main_module );
383     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
384
385     /* changing the instance doesn't make it global */
386     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0 );
387     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
388     check_class( kernel32, name, "kernel32" );
389     check_instance( name, kernel32, kernel32, kernel32 );
390     check_thread_instance( name, kernel32, kernel32, kernel32 );
391     ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
392     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
393
394     /* GetClassInfo with instance 0 finds user32 instance */
395     SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)user32 );
396     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
397     check_class( kernel32, name, "kernel32" );
398     check_class( user32, name, "main_module" );
399     check_class( 0, name, "main_module" );
400     check_instance( name, kernel32, kernel32, kernel32 );
401     check_instance( name, user32, 0, user32 );
402     check_instance( name, 0, 0, kernel32 );
403     check_thread_instance( name, kernel32, kernel32, kernel32 );
404     check_thread_instance( name, user32, 0, user32 );
405     check_thread_instance( name, 0, 0, kernel32 );
406     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
407
408     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0x12345678 );
409     ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
410     check_class( kernel32, name, "kernel32" );
411     check_class( (HINSTANCE)0x12345678, name, "main_module" );
412     check_instance( name, kernel32, kernel32, kernel32 );
413     check_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
414     check_thread_instance( name, kernel32, kernel32, kernel32 );
415     check_thread_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
416     ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
417
418     /* creating a window with instance 0 uses the first class found */
419     cls.hInstance = (HINSTANCE)0xdeadbeef;
420     cls.lpszMenuName = "deadbeef";
421     cls.style = 3;
422     ok( RegisterClassA( &cls ), "Failed to register local class for deadbeef\n" );
423     hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
424     ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0xdeadbeef,
425         "Didn't get deadbeef class for null instance\n" );
426     DestroyWindow( hwnd2 );
427     ok( UnregisterClassA( name, (HINSTANCE)0xdeadbeef ), "Unregister failed for deadbeef\n" );
428
429     hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
430     ok( (HINSTANCE)GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == kernel32,
431         "Didn't get kernel32 class for null instance\n" );
432     DestroyWindow( hwnd2 );
433
434     r = GetClassName( hwnd, buffer, 4 );
435     ok( r == 3, "expected 3, got %d\n", r );
436     ok( !strcmp( buffer, "__t"), "name wrong: %s\n", buffer );
437
438     ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
439
440     hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
441     ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0x12345678,
442         "Didn't get 12345678 class for null instance\n" );
443     DestroyWindow( hwnd2 );
444
445     SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)main_module );
446     DestroyWindow( hwnd );
447
448     /* null handle means the same thing as main module */
449     cls.lpszMenuName  = "null";
450     cls.hInstance = 0;
451     ok( !RegisterClassA( &cls ), "Succeeded registering local class for null instance\n" );
452     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
453     ok( UnregisterClassA( name, main_module ), "Unregister failed for main module\n" );
454
455     ok( RegisterClassA( &cls ), "Failed to register local class for null instance\n" );
456     /* must be found with main module handle */
457     check_class( main_module, name, "null" );
458     check_instance( name, main_module, main_module, main_module );
459     check_thread_instance( name, main_module, main_module, main_module );
460     ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
461     ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
462     ok( UnregisterClassA( name, 0 ), "Unregister failed for null instance\n" );
463
464     /* registering for user32 always fails */
465     cls.lpszMenuName = "user32";
466     cls.hInstance = user32;
467     ok( !RegisterClassA( &cls ), "Succeeded registering local class for user32\n" );
468     ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
469     cls.style |= CS_GLOBALCLASS;
470     ok( !RegisterClassA( &cls ), "Succeeded registering global class for user32\n" );
471     ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
472
473     /* unregister is OK though */
474     cls.hInstance = main_module;
475     ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
476     ok( UnregisterClassA( name, user32 ), "Unregister failed for user32\n" );
477
478     /* instance doesn't matter for global class */
479     cls.style |= CS_GLOBALCLASS;
480     cls.lpszMenuName  = "main_module";
481     cls.hInstance = main_module;
482     ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
483     cls.lpszMenuName  = "kernel32";
484     cls.hInstance = kernel32;
485     ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
486     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
487     /* even if global flag is cleared */
488     hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
489     SetClassLongA( hwnd, GCL_STYLE, 0 );
490     ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
491     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
492
493     check_class( main_module, name, "main_module" );
494     check_class( kernel32, name, "main_module" );
495     check_class( 0, name, "main_module" );
496     check_class( (HINSTANCE)0x12345678, name, "main_module" );
497     check_instance( name, main_module, main_module, main_module );
498     check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
499     check_thread_instance( name, main_module, main_module, main_module );
500     check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
501
502     /* changing the instance for global class doesn't make much difference */
503     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
504     check_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
505     check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
506     check_thread_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
507     check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
508
509     DestroyWindow( hwnd );
510     ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
511     ok( !UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister succeeded the second time\n" );
512     ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
513
514     cls.hInstance = (HINSTANCE)0x12345678;
515     ok( RegisterClassA( &cls ), "Failed to register global class for dummy instance\n" );
516     check_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
517     check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
518     check_thread_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
519     check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
520     ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
521
522     /* check system classes */
523
524     /* we cannot register a global class with the name of a system class */
525     cls.style |= CS_GLOBALCLASS;
526     cls.lpszMenuName  = "button_main_module";
527     cls.lpszClassName = "BUTTON";
528     cls.hInstance = main_module;
529     ok( !RegisterClassA( &cls ), "Succeeded registering global button class for main module\n" );
530     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
531     cls.hInstance = kernel32;
532     ok( !RegisterClassA( &cls ), "Succeeded registering global button class for kernel32\n" );
533     ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
534
535     /* local class is OK however */
536     cls.style &= ~CS_GLOBALCLASS;
537     cls.lpszMenuName  = "button_main_module";
538     cls.hInstance = main_module;
539     ok( RegisterClassA( &cls ), "Failed to register local button class for main module\n" );
540     check_class( main_module, "BUTTON", "button_main_module" );
541     cls.lpszMenuName  = "button_kernel32";
542     cls.hInstance = kernel32;
543     ok( RegisterClassA( &cls ), "Failed to register local button class for kernel32\n" );
544     check_class( kernel32, "BUTTON", "button_kernel32" );
545     check_class( main_module, "BUTTON", "button_main_module" );
546     ok( UnregisterClassA( "BUTTON", kernel32 ), "Unregister failed for kernel32 button\n" );
547     ok( UnregisterClassA( "BUTTON", main_module ), "Unregister failed for main module button\n" );
548     /* GetClassInfo sets instance to passed value for global classes */
549     check_instance( "BUTTON", 0, 0, user32 );
550     check_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
551     check_instance( "BUTTON", user32, 0, user32 );
552     check_thread_instance( "BUTTON", 0, 0, user32 );
553     check_thread_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
554     check_thread_instance( "BUTTON", user32, 0, user32 );
555
556     /* we can unregister system classes */
557     ok( GetClassInfo( 0, "BUTTON", &wc ), "Button class not found with null instance\n" );
558     ok( GetClassInfo( kernel32, "BUTTON", &wc ), "Button class not found with kernel32\n" );
559     ok( UnregisterClass( "BUTTON", (HINSTANCE)0x12345678 ), "Failed to unregister button\n" );
560     ok( !UnregisterClass( "BUTTON", (HINSTANCE)0x87654321 ), "Unregistered button a second time\n" );
561     ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
562     ok( !GetClassInfo( 0, "BUTTON", &wc ), "Button still exists\n" );
563     /* last error not set reliably */
564
565     /* we can change the instance of a system class */
566     check_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
567     check_thread_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
568     hwnd = CreateWindowExA( 0, "EDIT", "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
569     SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
570     check_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
571     check_thread_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
572 }
573
574 static void test_builtinproc(void)
575 {
576     /* Edit behaves differently */
577     static const CHAR NORMAL_CLASSES[][10] = {
578         "Button",
579         "Static",
580         "ComboBox",
581         "ComboLBox",
582         "ListBox",
583         "ScrollBar",
584         "#32770",  /* dialog */
585     };
586     static const int NUM_NORMAL_CLASSES = (sizeof(NORMAL_CLASSES)/sizeof(NORMAL_CLASSES[0]));
587     static const char classA[] = "deftest";
588     static const WCHAR classW[] = {'d','e','f','t','e','s','t',0};
589     WCHAR unistring[] = {0x142, 0x40e, 0x3b4, 0};  /* a string that would be destroyed by a W->A->W conversion */
590     WNDPROC pDefWindowProcA, pDefWindowProcW;
591     WNDPROC oldproc;
592     WNDCLASSEXA cls;  /* the memory layout of WNDCLASSEXA and WNDCLASSEXW is the same */
593     WCHAR buf[128];
594     ATOM atom;
595     HWND hwnd;
596     int i;
597
598     pDefWindowProcA = GetProcAddress(GetModuleHandle("user32.dll"), "DefWindowProcA");
599     pDefWindowProcW = GetProcAddress(GetModuleHandle("user32.dll"), "DefWindowProcW");
600
601     for (i = 0; i < 4; i++)
602     {
603         ZeroMemory(&cls, sizeof(cls));
604         cls.cbSize = sizeof(cls);
605         cls.hInstance = GetModuleHandle(NULL);
606         cls.hbrBackground = GetStockObject (WHITE_BRUSH);
607         if (i & 1)
608             cls.lpfnWndProc = pDefWindowProcA;
609         else
610             cls.lpfnWndProc = pDefWindowProcW;
611
612         if (i & 2)
613         {
614             cls.lpszClassName = classA;
615             atom = RegisterClassExA(&cls);
616         }
617         else
618         {
619             cls.lpszClassName = (LPCSTR)classW;
620             atom = RegisterClassExW((WNDCLASSEXW *)&cls);
621         }
622         ok(atom != 0, "Couldn't register class, i=%d, %d\n", i, GetLastError());
623
624         hwnd = CreateWindowA(classA, NULL, 0, 0, 0, 100, 100, NULL, NULL, GetModuleHandle(NULL), NULL);
625         ok(hwnd != NULL, "Couldn't create window i=%d\n", i);
626
627         ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
628             (void *)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), pDefWindowProcA);
629         ok(GetClassLongPtrA(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
630             (void *)GetClassLongPtrA(hwnd, GCLP_WNDPROC), pDefWindowProcA);
631
632         ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
633             (void *)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), pDefWindowProcW);
634         ok(GetClassLongPtrW(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
635             (void *)GetClassLongPtrW(hwnd, GCLP_WNDPROC), pDefWindowProcW);
636
637         DestroyWindow(hwnd);
638         UnregisterClass((LPSTR)(DWORD_PTR)atom, GetModuleHandle(NULL));
639     }
640
641     /* built-in winproc - window A/W type automatically detected */
642     ZeroMemory(&cls, sizeof(cls));
643     cls.cbSize = sizeof(cls);
644     cls.hInstance = GetModuleHandle(NULL);
645     cls.hbrBackground = GetStockObject (WHITE_BRUSH);
646     cls.lpszClassName = classA;
647     cls.lpfnWndProc = pDefWindowProcW;
648     atom = RegisterClassExA(&cls);
649
650     hwnd = CreateWindowExW(0, classW, NULL, WS_OVERLAPPEDWINDOW,
651         CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
652     ok(IsWindowUnicode(hwnd), "Windows should be Unicode\n");
653     SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)pDefWindowProcA);
654     ok(IsWindowUnicode(hwnd), "Windows should have remained Unicode\n");
655     ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Invalid ANSI winproc\n");
656     ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Invalid Unicode winproc\n");
657     SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
658     ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have switched window to ANSI\n");
659
660     DestroyWindow(hwnd);
661     UnregisterClass((LPSTR)(DWORD_PTR)atom, GetModuleHandle(NULL));
662
663     /* custom winproc - the same function can be used as both A and W*/
664     ZeroMemory(&cls, sizeof(cls));
665     cls.cbSize = sizeof(cls);
666     cls.hInstance = GetModuleHandle(NULL);
667     cls.hbrBackground = GetStockObject (WHITE_BRUSH);
668     cls.lpszClassName = classA;
669     cls.lpfnWndProc = ClassTest_WndProc2;
670     atom = RegisterClassExA(&cls);
671
672     hwnd = CreateWindowExW(0, classW, NULL, WS_OVERLAPPEDWINDOW,
673         CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
674     ok(IsWindowUnicode(hwnd) == FALSE, "Window should be ANSI\n");
675     SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
676     ok(IsWindowUnicode(hwnd), "SetWindowLongPtrW should have changed window to Unicode\n");
677     SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
678     ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
679
680     DestroyWindow(hwnd);
681     UnregisterClass((LPSTR)(DWORD_PTR)atom, GetModuleHandle(NULL));
682
683     /* For most of the builtin controls both GetWindowLongPtrA and W returns a pointer that is executed directly
684      * by CallWindowProcA/W */
685     for (i = 0; i < NUM_NORMAL_CLASSES; i++)
686     {
687         WNDPROC procA, procW;
688         hwnd = CreateWindowExA(0, NORMAL_CLASSES[i], classA, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 680, 260,
689             NULL, NULL, NULL, 0);
690         ok(hwnd != NULL, "Couldn't create window of class %s\n", NORMAL_CLASSES[i]);
691         SetWindowText(hwnd, classA);  /* ComboBox needs this */
692         procA = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
693         procW = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
694         ok(!IS_WNDPROC_HANDLE(procA), "procA should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procA);
695         ok(!IS_WNDPROC_HANDLE(procW), "procW should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procW);
696         CallWindowProcA(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
697         ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT A/A invalid return for class %s\n", NORMAL_CLASSES[i]);
698         CallWindowProcA(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
699         ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT A/W invalid return for class %s\n", NORMAL_CLASSES[i]);
700         CallWindowProcW(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
701         ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT W/A invalid return for class %s\n", NORMAL_CLASSES[i]);
702         CallWindowProcW(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
703         ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT W/W invalid return for class %s\n", NORMAL_CLASSES[i]);
704
705         oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
706         ok(IS_WNDPROC_HANDLE(oldproc) == FALSE, "Class %s shouldn't return a handle\n", NORMAL_CLASSES[i]);
707         DestroyWindow(hwnd);
708     }
709
710     /* Edit controls are special - they return a wndproc handle when GetWindowLongPtr is called with a different A/W.
711      * On the other hand there is no W->A->W conversion so this control is treated specially. */
712     hwnd = CreateWindowW(WC_EDITW, unistring, WS_OVERLAPPEDWINDOW,
713       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
714     /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
715     ok(IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a Unicode wndproc\n");
716     ok(IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a ANSI wndproc\n");
717     /* But GetWindowLongPtr returns only a handle for the ANSI one */
718     ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
719     ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return a W wndproc handle\n");
720     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
721     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
722     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
723     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
724     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
725     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
726
727     SetWindowTextW(hwnd, classW);
728     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
729     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
730
731     oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc2);
732     /* SetWindowLongPtr returns a wndproc handle - like GetWindowLongPtr */
733     ok(IS_WNDPROC_HANDLE(oldproc), "Edit control should return a wndproc handle\n");
734     ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
735     SetWindowTextA(hwnd, classA);  /* Windows resets the title to WideStringToMultiByte(unistring) */
736     memset(buf, 0, sizeof(buf));
737     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
738     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
739     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
740     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
741     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
742     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
743
744     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
745     ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
746
747     DestroyWindow(hwnd);
748
749     hwnd = CreateWindowA(WC_EDITA, classA, WS_OVERLAPPEDWINDOW,
750       CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
751
752     /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
753     ok(!IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)), "Edit control class should have a Unicode wndproc\n");
754     ok(!IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)), "Edit control class should have a ANSI wndproc\n");
755     /* But GetWindowLongPtr returns only a handle for the Unicode one */
756     ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return an A wndproc handle\n");
757     ok(IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
758     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
759     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
760     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
761     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
762     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
763     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
764
765     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
766     ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
767
768     SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
769     SetWindowTextW(hwnd, unistring);
770     CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
771     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
772     CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
773     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
774     CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
775     ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
776
777     SetWindowTextW(hwnd, classW);
778     CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
779     ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
780
781     DestroyWindow(hwnd);
782 }
783
784
785 static LRESULT WINAPI TestDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
786 {
787     return DefWindowProc(hWnd, uMsg, wParam, lParam);
788 }
789
790 static BOOL RegisterTestDialog(HINSTANCE hInstance)
791 {
792     WNDCLASSEX wcx;
793     ATOM atom = 0;
794
795     ZeroMemory(&wcx, sizeof(WNDCLASSEX));
796     wcx.cbSize = sizeof(wcx);
797     wcx.lpfnWndProc = TestDlgProc;
798     wcx.cbClsExtra = 0;
799     wcx.cbWndExtra = DLGWINDOWEXTRA;
800     wcx.hInstance = hInstance;
801     wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
802     wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
803     wcx.hbrBackground = GetStockObject(WHITE_BRUSH);
804     wcx.lpszClassName = "TestDialog";
805     wcx.lpszMenuName =  "TestDialog";
806     wcx.hIconSm = LoadImage(hInstance, MAKEINTRESOURCE(5), IMAGE_ICON,
807         GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
808         LR_DEFAULTCOLOR);
809
810     atom = RegisterClassEx(&wcx);
811     ok(atom != 0, "RegisterClassEx returned 0\n");
812
813     return atom;
814 }
815
816 /* test registering a dialog box created by using the CLASS directive in a
817    resource file, then test creating the dialog using CreateDialogParam. */
818 static void CreateDialogParamTest(HINSTANCE hInstance)
819 {
820     HWND hWndMain;
821
822     if (RegisterTestDialog(hInstance))
823     {
824         hWndMain = CreateDialogParam(hInstance, "CLASS_TEST_DIALOG", NULL, 0, 0);
825         ok(hWndMain != NULL, "CreateDialogParam returned NULL\n");
826         ShowWindow(hWndMain, SW_SHOW);
827         DestroyWindow(hWndMain);
828     }
829 }
830
831 START_TEST(class)
832 {
833     HANDLE hInstance = GetModuleHandleA( NULL );
834
835     if (!GetModuleHandleW(0))
836     {
837         trace("Class test is incompatible with Win9x implementation, skipping\n");
838         return;
839     }
840
841     ClassTest(hInstance,FALSE);
842     ClassTest(hInstance,TRUE);
843     CreateDialogParamTest(hInstance);
844     test_styles();
845     test_builtinproc();
846
847     /* this test unregisters the Button class so it should be executed at the end */
848     test_instances();
849 }