1 /* Unit test suite for window classes.
3 * Copyright 2002 Mike McCormack
4 * Copyright 2003 Alexandre Julliard
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.
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.
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
21 /* To get CS_DROPSHADOW with the MSVC headers */
22 #define _WIN32_WINNT 0x0501
29 #include "wine/test.h"
36 #define NUMCLASSWORDS 4
38 static LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
40 return DefWindowProcW (hWnd, msg, wParam, lParam);
43 /***********************************************************************
45 static void ClassTest(HINSTANCE hInstance, BOOL global)
48 static const WCHAR className[] = {'T','e','s','t','C','l','a','s','s',0};
49 static const WCHAR winName[] = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
56 cls.style = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
57 cls.lpfnWndProc = ClassTest_WndProc;
58 cls.cbClsExtra = NUMCLASSWORDS*sizeof(DWORD);
60 cls.hInstance = hInstance;
61 cls.hIcon = LoadIconW (0, (LPWSTR)IDI_APPLICATION);
62 cls.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
63 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
65 cls.lpszClassName = className;
67 classatom=RegisterClassW(&cls);
68 if (!classatom && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
70 ok(classatom, "failed to register class\n");
72 ok(!RegisterClassW (&cls),
73 "RegisterClass of the same class should fail for the second time\n");
76 hTestWnd = CreateWindowW (className, winName,
77 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
78 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
81 ok(hTestWnd!=0, "Failed to create window\n");
83 /* test initial values of valid classwords */
84 for(i=0; i<NUMCLASSWORDS; i++)
87 ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
88 "GetClassLongW initial value nonzero!\n");
90 "GetClassLongW failed!\n");
96 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
97 * does not fail on Win 98, though MSDN says it should
100 GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
102 "GetClassLongW() with invalid offset did not fail\n");
105 /* set values of valid class words */
106 for(i=0; i<NUMCLASSWORDS; i++)
109 ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
110 "GetClassLongW(%d) initial value nonzero!\n",i);
112 "SetClassLongW(%d) failed!\n",i);
115 /* test values of valid classwords that we set */
116 for(i=0; i<NUMCLASSWORDS; i++)
119 ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
120 "GetClassLongW value doesn't match what was set!\n");
122 "GetClassLongW failed!\n");
125 /* check GetClassName */
126 i = GetClassNameW(hTestWnd, str, sizeof(str));
127 ok(i == lstrlenW(className),
128 "GetClassName returned incorrect length\n");
129 ok(!lstrcmpW(className,str),
130 "GetClassName returned incorrect name for this window's class\n");
132 /* check GetClassInfo with our hInstance */
133 if((test_atom = GetClassInfoW(hInstance, str, &wc)))
135 ok(test_atom == classatom,
136 "class atom did not match\n");
137 ok(wc.cbClsExtra == cls.cbClsExtra,
138 "cbClsExtra did not match\n");
139 ok(wc.cbWndExtra == cls.cbWndExtra,
140 "cbWndExtra did not match\n");
141 ok(wc.hbrBackground == cls.hbrBackground,
142 "hbrBackground did not match\n");
143 ok(wc.hCursor== cls.hCursor,
144 "hCursor did not match\n");
145 ok(wc.hInstance== cls.hInstance,
146 "hInstance did not match\n");
149 ok(FALSE,"GetClassInfo (hinstance) failed!\n");
151 /* check GetClassInfo with zero hInstance */
154 if((test_atom = GetClassInfoW(0, str, &wc)))
156 ok(test_atom == classatom,
157 "class atom did not match %x != %x\n", test_atom, classatom);
158 ok(wc.cbClsExtra == cls.cbClsExtra,
159 "cbClsExtra did not match %x!=%x\n",wc.cbClsExtra,cls.cbClsExtra);
160 ok(wc.cbWndExtra == cls.cbWndExtra,
161 "cbWndExtra did not match %x!=%x\n",wc.cbWndExtra,cls.cbWndExtra);
162 ok(wc.hbrBackground == cls.hbrBackground,
163 "hbrBackground did not match %p!=%p\n",wc.hbrBackground,cls.hbrBackground);
164 ok(wc.hCursor== cls.hCursor,
165 "hCursor did not match %p!=%p\n",wc.hCursor,cls.hCursor);
167 "hInstance not zero for global class %p\n",wc.hInstance);
170 ok(FALSE,"GetClassInfo (0) failed for global class!\n");
174 ok(!GetClassInfoW(0, str, &wc),
175 "GetClassInfo (0) succeeded for local class!\n");
178 ok(!UnregisterClassW(className, hInstance),
179 "Unregister class succeeded with window existing\n");
181 ok(DestroyWindow(hTestWnd),
182 "DestroyWindow() failed!\n");
184 ok(UnregisterClassW(className, hInstance),
185 "UnregisterClass() failed\n");
190 static void check_style( const char *name, int must_exist, UINT style, UINT ignore )
194 if (GetClassInfo( 0, name, &wc ))
196 ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n",
197 name, ~wc.style & style, wc.style, style );
198 ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n",
199 name, wc.style & ~style, wc.style, style );
202 ok( !must_exist, "System class %s does not exist\n", name );
205 /* test styles of system classes */
206 static void test_styles(void)
208 /* check style bits */
209 check_style( "Button", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
210 check_style( "ComboBox", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
211 check_style( "Edit", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
212 check_style( "ListBox", 1, CS_PARENTDC | CS_DBLCLKS, CS_PARENTDC /*FIXME*/ );
213 check_style( "MDIClient", 1, 0, 0 );
214 check_style( "ScrollBar", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
215 check_style( "Static", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
216 check_style( "ComboLBox", 1, CS_SAVEBITS | CS_DBLCLKS, 0 );
217 check_style( "DDEMLEvent", 0, 0, 0 );
218 check_style( "Message", 0, 0, 0 );
219 check_style( "#32768", 1, CS_DROPSHADOW | CS_SAVEBITS | CS_DBLCLKS, CS_DROPSHADOW ); /* menu */
220 check_style( "#32769", 1, CS_DBLCLKS, 0 ); /* desktop */
221 check_style( "#32770", 1, CS_SAVEBITS | CS_DBLCLKS, 0 ); /* dialog */
222 todo_wine { check_style( "#32771", 1, CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW, 0 ); } /* task switch */
223 check_style( "#32772", 1, 0, 0 ); /* icon title */
226 static void check_class(HINSTANCE inst, const char *name, const char *menu_name)
229 UINT atom = GetClassInfo(inst,name,&wc);
230 ok( atom, "Class %s %p not found\n", name, inst );
233 if (wc.lpszMenuName && menu_name)
234 ok( !strcmp( menu_name, wc.lpszMenuName ), "Wrong name %s/%s for class %s %p\n",
235 wc.lpszMenuName, menu_name, name, inst );
237 ok( !menu_name == !wc.lpszMenuName, "Wrong name %p/%p for class %s %p\n",
238 wc.lpszMenuName, menu_name, name, inst );
242 static void check_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
247 ok( GetClassInfo( inst, name, &wc ), "Couldn't find class %s inst %p\n", name, inst );
248 ok( wc.hInstance == info_inst, "Wrong info instance %p/%p for class %s\n",
249 wc.hInstance, info_inst, name );
250 hwnd = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, inst, 0 );
251 ok( hwnd != NULL, "Couldn't create window for class %s inst %p\n", name, inst );
252 ok( (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ) == gcl_inst,
253 "Wrong GCL instance %p/%p for class %s\n",
254 (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ), gcl_inst, name );
255 ok( (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ) == inst,
256 "Wrong GWL instance %p/%p for window %s\n",
257 (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), inst, name );
258 ok(!UnregisterClassA(name, inst), "UnregisterClassA should fail while exists a class window\n");
259 ok(GetLastError() == ERROR_CLASS_HAS_WINDOWS, "GetLastError() should be set to ERROR_CLASS_HAS_WINDOWS not %d\n", GetLastError());
266 HINSTANCE inst, info_inst, gcl_inst;
269 static DWORD WINAPI thread_proc(void *param)
271 struct class_info *class_info = (struct class_info *)param;
273 check_instance(class_info->name, class_info->inst, class_info->info_inst, class_info->gcl_inst);
278 static void check_thread_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
282 struct class_info class_info;
284 class_info.name = name;
285 class_info.inst = inst;
286 class_info.info_inst = info_inst;
287 class_info.gcl_inst = gcl_inst;
289 hThread = CreateThread(NULL, 0, thread_proc, &class_info, 0, &tid);
290 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
291 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
292 CloseHandle(hThread);
295 /* test various instance parameters */
296 static void test_instances(void)
300 const char *name = "__test__";
301 HINSTANCE kernel32 = GetModuleHandleA("kernel32");
302 HINSTANCE user32 = GetModuleHandleA("user32");
303 HINSTANCE main_module = GetModuleHandleA(NULL);
307 memset( &cls, 0, sizeof(cls) );
308 cls.style = CS_HREDRAW | CS_VREDRAW;
309 cls.lpfnWndProc = ClassTest_WndProc;
312 cls.lpszClassName = name;
314 cls.lpszMenuName = "main_module";
315 cls.hInstance = main_module;
317 ok( RegisterClassA( &cls ), "Failed to register local class for main module\n" );
318 check_class( main_module, name, "main_module" );
319 check_instance( name, main_module, main_module, main_module );
320 check_thread_instance( name, main_module, main_module, main_module );
322 cls.lpszMenuName = "kernel32";
323 cls.hInstance = kernel32;
324 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
325 check_class( kernel32, name, "kernel32" );
326 check_class( main_module, name, "main_module" );
327 check_instance( name, kernel32, kernel32, kernel32 );
328 check_thread_instance( name, kernel32, kernel32, kernel32 );
329 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
331 /* Bug 2631 - Supplying an invalid number of bytes fails */
334 SetLastError(0xdeadbeef);
335 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
336 "Failed with invalid number of WndExtra bytes\n");
340 SetLastError(0xdeadbeef);
341 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
342 "Failed with invalid number of ClsExtra bytes\n");
346 SetLastError(0xdeadbeef);
347 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
348 "Failed with invalid number of ClsExtra and cbWndExtra bytes\n");
352 SetLastError(0xdeadbeef);
354 /* setting global flag doesn't change status of class */
355 hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
356 SetClassLongA( hwnd, GCL_STYLE, CS_GLOBALCLASS );
357 cls.lpszMenuName = "kernel32";
358 cls.hInstance = kernel32;
359 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
360 check_class( kernel32, name, "kernel32" );
361 check_class( main_module, name, "main_module" );
362 check_instance( name, kernel32, kernel32, kernel32 );
363 check_instance( name, main_module, main_module, main_module );
364 check_thread_instance( name, kernel32, kernel32, kernel32 );
365 check_thread_instance( name, main_module, main_module, main_module );
366 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
368 /* changing the instance doesn't make it global */
369 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0 );
370 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
371 check_class( kernel32, name, "kernel32" );
372 check_instance( name, kernel32, kernel32, kernel32 );
373 check_thread_instance( name, kernel32, kernel32, kernel32 );
374 ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
375 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
377 /* GetClassInfo with instance 0 finds user32 instance */
378 SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)user32 );
379 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
380 check_class( kernel32, name, "kernel32" );
381 check_class( user32, name, "main_module" );
382 check_class( 0, name, "main_module" );
383 check_instance( name, kernel32, kernel32, kernel32 );
384 check_instance( name, user32, 0, user32 );
385 check_instance( name, 0, 0, kernel32 );
386 check_thread_instance( name, kernel32, kernel32, kernel32 );
387 check_thread_instance( name, user32, 0, user32 );
388 check_thread_instance( name, 0, 0, kernel32 );
389 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
391 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0x12345678 );
392 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
393 check_class( kernel32, name, "kernel32" );
394 check_class( (HINSTANCE)0x12345678, name, "main_module" );
395 check_instance( name, kernel32, kernel32, kernel32 );
396 check_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
397 check_thread_instance( name, kernel32, kernel32, kernel32 );
398 check_thread_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
399 ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
401 /* creating a window with instance 0 uses the first class found */
402 cls.hInstance = (HINSTANCE)0xdeadbeef;
403 cls.lpszMenuName = "deadbeef";
405 ok( RegisterClassA( &cls ), "Failed to register local class for deadbeef\n" );
406 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
407 ok( (HINSTANCE)GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == (HINSTANCE)0xdeadbeef,
408 "Didn't get deadbeef class for null instance\n" );
409 DestroyWindow( hwnd2 );
410 ok( UnregisterClassA( name, (HINSTANCE)0xdeadbeef ), "Unregister failed for deadbeef\n" );
412 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
413 ok( (HINSTANCE)GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == kernel32,
414 "Didn't get kernel32 class for null instance\n" );
415 DestroyWindow( hwnd2 );
417 r = GetClassName( hwnd, buffer, 4 );
418 ok( r == 3, "expected 3, got %d\n", r );
419 ok( !strcmp( buffer, "__t"), "name wrong: %s\n", buffer );
421 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
423 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
424 ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0x12345678,
425 "Didn't get 12345678 class for null instance\n" );
426 DestroyWindow( hwnd2 );
428 SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)main_module );
429 DestroyWindow( hwnd );
431 /* null handle means the same thing as main module */
432 cls.lpszMenuName = "null";
434 ok( !RegisterClassA( &cls ), "Succeeded registering local class for null instance\n" );
435 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
436 ok( UnregisterClassA( name, main_module ), "Unregister failed for main module\n" );
438 ok( RegisterClassA( &cls ), "Failed to register local class for null instance\n" );
439 /* must be found with main module handle */
440 check_class( main_module, name, "null" );
441 check_instance( name, main_module, main_module, main_module );
442 check_thread_instance( name, main_module, main_module, main_module );
443 ok( !GetClassInfo( 0, name, &wc ), "Class found with null instance\n" );
444 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
445 ok( UnregisterClassA( name, 0 ), "Unregister failed for null instance\n" );
447 /* registering for user32 always fails */
448 cls.lpszMenuName = "user32";
449 cls.hInstance = user32;
450 ok( !RegisterClassA( &cls ), "Succeeded registering local class for user32\n" );
451 ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
452 cls.style |= CS_GLOBALCLASS;
453 ok( !RegisterClassA( &cls ), "Succeeded registering global class for user32\n" );
454 ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
456 /* unregister is OK though */
457 cls.hInstance = main_module;
458 ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
459 ok( UnregisterClassA( name, user32 ), "Unregister failed for user32\n" );
461 /* instance doesn't matter for global class */
462 cls.style |= CS_GLOBALCLASS;
463 cls.lpszMenuName = "main_module";
464 cls.hInstance = main_module;
465 ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
466 cls.lpszMenuName = "kernel32";
467 cls.hInstance = kernel32;
468 ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
469 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
470 /* even if global flag is cleared */
471 hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
472 SetClassLongA( hwnd, GCL_STYLE, 0 );
473 ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
474 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
476 check_class( main_module, name, "main_module" );
477 check_class( kernel32, name, "main_module" );
478 check_class( 0, name, "main_module" );
479 check_class( (HINSTANCE)0x12345678, name, "main_module" );
480 check_instance( name, main_module, main_module, main_module );
481 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
482 check_thread_instance( name, main_module, main_module, main_module );
483 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
485 /* changing the instance for global class doesn't make much difference */
486 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
487 check_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
488 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
489 check_thread_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
490 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
492 DestroyWindow( hwnd );
493 ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
494 ok( !UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister succeeded the second time\n" );
495 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
497 cls.hInstance = (HINSTANCE)0x12345678;
498 ok( RegisterClassA( &cls ), "Failed to register global class for dummy instance\n" );
499 check_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
500 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
501 check_thread_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
502 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
503 ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
505 /* check system classes */
507 /* we cannot register a global class with the name of a system class */
508 cls.style |= CS_GLOBALCLASS;
509 cls.lpszMenuName = "button_main_module";
510 cls.lpszClassName = "BUTTON";
511 cls.hInstance = main_module;
512 ok( !RegisterClassA( &cls ), "Succeeded registering global button class for main module\n" );
513 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
514 cls.hInstance = kernel32;
515 ok( !RegisterClassA( &cls ), "Succeeded registering global button class for kernel32\n" );
516 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
518 /* local class is OK however */
519 cls.style &= ~CS_GLOBALCLASS;
520 cls.lpszMenuName = "button_main_module";
521 cls.hInstance = main_module;
522 ok( RegisterClassA( &cls ), "Failed to register local button class for main module\n" );
523 check_class( main_module, "BUTTON", "button_main_module" );
524 cls.lpszMenuName = "button_kernel32";
525 cls.hInstance = kernel32;
526 ok( RegisterClassA( &cls ), "Failed to register local button class for kernel32\n" );
527 check_class( kernel32, "BUTTON", "button_kernel32" );
528 check_class( main_module, "BUTTON", "button_main_module" );
529 ok( UnregisterClassA( "BUTTON", kernel32 ), "Unregister failed for kernel32 button\n" );
530 ok( UnregisterClassA( "BUTTON", main_module ), "Unregister failed for main module button\n" );
531 /* GetClassInfo sets instance to passed value for global classes */
532 check_instance( "BUTTON", 0, 0, user32 );
533 check_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
534 check_instance( "BUTTON", user32, 0, user32 );
535 check_thread_instance( "BUTTON", 0, 0, user32 );
536 check_thread_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
537 check_thread_instance( "BUTTON", user32, 0, user32 );
539 /* we can unregister system classes */
540 ok( GetClassInfo( 0, "BUTTON", &wc ), "Button class not found with null instance\n" );
541 ok( GetClassInfo( kernel32, "BUTTON", &wc ), "Button class not found with kernel32\n" );
542 ok( UnregisterClass( "BUTTON", (HINSTANCE)0x12345678 ), "Failed to unregister button\n" );
543 ok( !UnregisterClass( "BUTTON", (HINSTANCE)0x87654321 ), "Unregistered button a second time\n" );
544 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
545 ok( !GetClassInfo( 0, "BUTTON", &wc ), "Button still exists\n" );
546 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST ||
547 GetLastError() == ERROR_INVALID_PARAMETER /* W2K3 */,
548 "Wrong error code %d\n", GetLastError() );
550 /* we can change the instance of a system class */
551 check_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
552 check_thread_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
553 hwnd = CreateWindowExA( 0, "EDIT", "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
554 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
555 check_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
556 check_thread_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
559 static LRESULT WINAPI TestDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
561 return DefWindowProc(hWnd, uMsg, wParam, lParam);
564 static BOOL RegisterTestDialog(HINSTANCE hInstance)
569 ZeroMemory(&wcx, sizeof(WNDCLASSEX));
570 wcx.cbSize = sizeof(wcx);
571 wcx.lpfnWndProc = TestDlgProc;
573 wcx.cbWndExtra = DLGWINDOWEXTRA;
574 wcx.hInstance = hInstance;
575 wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
576 wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
577 wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
578 wcx.lpszClassName = "TestDialog";
579 wcx.lpszMenuName = "TestDialog";
580 wcx.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(5),
582 GetSystemMetrics(SM_CXSMICON),
583 GetSystemMetrics(SM_CYSMICON),
586 atom = RegisterClassEx(&wcx);
587 ok(atom != 0, "RegisterClassEx returned 0\n");
592 /* test registering a dialog box created by using the CLASS directive in a
593 resource file, then test creating the dialog using CreateDialogParam. */
594 static void WINAPI CreateDialogParamTest(HINSTANCE hInstance)
598 if (RegisterTestDialog(hInstance))
600 hWndMain = CreateDialogParam(hInstance, "CLASS_TEST_DIALOG", NULL, 0, 0);
601 ok(hWndMain != NULL, "CreateDialogParam returned NULL\n");
602 ShowWindow(hWndMain, SW_SHOW);
603 DestroyWindow(hWndMain);
609 HANDLE hInstance = GetModuleHandleA( NULL );
611 if (!GetModuleHandleW(0))
613 trace("Class test is incompatible with Win9x implementation, skipping\n");
617 ClassTest(hInstance,FALSE);
618 ClassTest(hInstance,TRUE);
619 CreateDialogParamTest(hInstance);