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