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
28 #include "wine/test.h"
37 #define NUMCLASSWORDS 4
39 #define IS_WNDPROC_HANDLE(x) (((ULONG_PTR)(x) >> 16) == (~0u >> 16))
41 static LRESULT WINAPI
ClassTest_WndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
43 if (msg
== WM_NCCREATE
) return 1;
44 return DefWindowProcW (hWnd
, msg
, wParam
, lParam
);
47 static LRESULT WINAPI
ClassTest_WndProc2 (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
49 if (msg
== WM_NCCREATE
) return 1;
50 return DefWindowProcA (hWnd
, msg
, wParam
, lParam
);
53 /***********************************************************************
55 static void ClassTest(HINSTANCE hInstance
, BOOL global
)
58 static const WCHAR className
[] = {'T','e','s','t','C','l','a','s','s',0};
59 static const WCHAR winName
[] = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
66 cls
.style
= CS_HREDRAW
| CS_VREDRAW
| (global
?CS_GLOBALCLASS
:0);
67 cls
.lpfnWndProc
= ClassTest_WndProc
;
68 cls
.cbClsExtra
= NUMCLASSWORDS
*sizeof(DWORD
);
70 cls
.hInstance
= hInstance
;
71 cls
.hIcon
= LoadIconW (0, (LPWSTR
)IDI_APPLICATION
);
72 cls
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
73 cls
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
75 cls
.lpszClassName
= className
;
77 classatom
=RegisterClassW(&cls
);
78 if (!classatom
&& GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
80 ok(classatom
, "failed to register class\n");
82 ok(!RegisterClassW (&cls
),
83 "RegisterClass of the same class should fail for the second time\n");
86 hTestWnd
= CreateWindowW (className
, winName
,
87 WS_OVERLAPPEDWINDOW
+ WS_HSCROLL
+ WS_VSCROLL
,
88 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, 0,
91 ok(hTestWnd
!=0, "Failed to create window\n");
93 /* test initial values of valid classwords */
94 for(i
=0; i
<NUMCLASSWORDS
; i
++)
97 ok(!GetClassLongW(hTestWnd
,i
*sizeof (DWORD
)),
98 "GetClassLongW initial value nonzero!\n");
100 "GetClassLongW failed!\n");
106 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
107 * does not fail on Win 98, though MSDN says it should
110 GetClassLongW(hTestWnd
, NUMCLASSWORDS
*sizeof(DWORD
));
112 "GetClassLongW() with invalid offset did not fail\n");
115 /* set values of valid class words */
116 for(i
=0; i
<NUMCLASSWORDS
; i
++)
119 ok(!SetClassLongW(hTestWnd
,i
*sizeof(DWORD
),i
+1),
120 "GetClassLongW(%d) initial value nonzero!\n",i
);
122 "SetClassLongW(%d) failed!\n",i
);
125 /* test values of valid classwords that we set */
126 for(i
=0; i
<NUMCLASSWORDS
; i
++)
129 ok( (i
+1) == GetClassLongW(hTestWnd
,i
*sizeof (DWORD
)),
130 "GetClassLongW value doesn't match what was set!\n");
132 "GetClassLongW failed!\n");
135 /* check GetClassName */
136 i
= GetClassNameW(hTestWnd
, str
, sizeof(str
)/sizeof(str
[0]));
137 ok(i
== lstrlenW(className
),
138 "GetClassName returned incorrect length\n");
139 ok(!lstrcmpW(className
,str
),
140 "GetClassName returned incorrect name for this window's class\n");
142 /* check GetClassInfo with our hInstance */
143 if((test_atom
= GetClassInfoW(hInstance
, str
, &wc
)))
145 ok(test_atom
== classatom
,
146 "class atom did not match\n");
147 ok(wc
.cbClsExtra
== cls
.cbClsExtra
,
148 "cbClsExtra did not match\n");
149 ok(wc
.cbWndExtra
== cls
.cbWndExtra
,
150 "cbWndExtra did not match\n");
151 ok(wc
.hbrBackground
== cls
.hbrBackground
,
152 "hbrBackground did not match\n");
153 ok(wc
.hCursor
== cls
.hCursor
,
154 "hCursor did not match\n");
155 ok(wc
.hInstance
== cls
.hInstance
,
156 "hInstance did not match\n");
159 ok(FALSE
,"GetClassInfo (hinstance) failed!\n");
161 /* check GetClassInfo with zero hInstance */
164 if((test_atom
= GetClassInfoW(0, str
, &wc
)))
166 ok(test_atom
== classatom
,
167 "class atom did not match %x != %x\n", test_atom
, classatom
);
168 ok(wc
.cbClsExtra
== cls
.cbClsExtra
,
169 "cbClsExtra did not match %x!=%x\n",wc
.cbClsExtra
,cls
.cbClsExtra
);
170 ok(wc
.cbWndExtra
== cls
.cbWndExtra
,
171 "cbWndExtra did not match %x!=%x\n",wc
.cbWndExtra
,cls
.cbWndExtra
);
172 ok(wc
.hbrBackground
== cls
.hbrBackground
,
173 "hbrBackground did not match %p!=%p\n",wc
.hbrBackground
,cls
.hbrBackground
);
174 ok(wc
.hCursor
== cls
.hCursor
,
175 "hCursor did not match %p!=%p\n",wc
.hCursor
,cls
.hCursor
);
177 "hInstance not zero for global class %p\n",wc
.hInstance
);
180 ok(FALSE
,"GetClassInfo (0) failed for global class!\n");
184 ok(!GetClassInfoW(0, str
, &wc
),
185 "GetClassInfo (0) succeeded for local class!\n");
188 ok(!UnregisterClassW(className
, hInstance
),
189 "Unregister class succeeded with window existing\n");
191 ok(DestroyWindow(hTestWnd
),
192 "DestroyWindow() failed!\n");
194 ok(UnregisterClassW(className
, hInstance
),
195 "UnregisterClass() failed\n");
200 static void check_style( const char *name
, int must_exist
, UINT style
, UINT ignore
)
204 if (GetClassInfoA( 0, name
, &wc
))
206 ok( !(~wc
.style
& style
& ~ignore
), "System class %s is missing bits %x (%08x/%08x)\n",
207 name
, ~wc
.style
& style
, wc
.style
, style
);
208 ok( !(wc
.style
& ~style
), "System class %s has extra bits %x (%08x/%08x)\n",
209 name
, wc
.style
& ~style
, wc
.style
, style
);
212 ok( !must_exist
, "System class %s does not exist\n", name
);
215 /* test styles of system classes */
216 static void test_styles(void)
218 /* check style bits */
219 check_style( "Button", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
, 0 );
220 check_style( "ComboBox", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
, 0 );
221 check_style( "Edit", 1, CS_PARENTDC
| CS_DBLCLKS
, 0 );
222 check_style( "ListBox", 1, CS_PARENTDC
| CS_DBLCLKS
, CS_PARENTDC
/*FIXME*/ );
223 check_style( "MDIClient", 1, 0, 0 );
224 check_style( "ScrollBar", 1, CS_PARENTDC
| CS_DBLCLKS
| CS_HREDRAW
| CS_VREDRAW
, 0 );
225 check_style( "Static", 1, CS_PARENTDC
| CS_DBLCLKS
, 0 );
226 check_style( "ComboLBox", 1, CS_SAVEBITS
| CS_DBLCLKS
, 0 );
227 check_style( "DDEMLEvent", 0, 0, 0 );
228 check_style( "Message", 0, 0, 0 );
229 check_style( "#32768", 1, CS_DROPSHADOW
| CS_SAVEBITS
| CS_DBLCLKS
, CS_DROPSHADOW
); /* menu */
230 check_style( "#32769", 1, CS_DBLCLKS
, 0 ); /* desktop */
231 check_style( "#32770", 1, CS_SAVEBITS
| CS_DBLCLKS
, 0 ); /* dialog */
232 todo_wine
{ check_style( "#32771", 1, CS_SAVEBITS
| CS_HREDRAW
| CS_VREDRAW
, 0 ); } /* task switch */
233 check_style( "#32772", 1, 0, 0 ); /* icon title */
236 static void check_class_(int line
, HINSTANCE inst
, const char *name
, const char *menu_name
)
239 UINT atom
= GetClassInfoA(inst
,name
,&wc
);
240 ok_(__FILE__
,line
)( atom
, "Class %s %p not found\n", name
, inst
);
243 if (wc
.lpszMenuName
&& menu_name
)
244 ok_(__FILE__
,line
)( !strcmp( menu_name
, wc
.lpszMenuName
),
245 "Wrong name %s/%s for class %s %p\n",
246 wc
.lpszMenuName
, menu_name
, name
, inst
);
248 ok_(__FILE__
,line
)( !menu_name
== !wc
.lpszMenuName
, "Wrong name %p/%p for class %s %p\n",
249 wc
.lpszMenuName
, menu_name
, name
, inst
);
252 #define check_class(inst,name,menu) check_class_(__LINE__,inst,name,menu)
254 static void check_instance_( int line
, const char *name
, HINSTANCE inst
,
255 HINSTANCE info_inst
, HINSTANCE gcl_inst
)
260 ok_(__FILE__
,line
)( GetClassInfoA( inst
, name
, &wc
), "Couldn't find class %s inst %p\n", name
, inst
);
261 ok_(__FILE__
,line
)( wc
.hInstance
== info_inst
, "Wrong info instance %p/%p for class %s\n",
262 wc
.hInstance
, info_inst
, name
);
263 hwnd
= CreateWindowExA( 0, name
, "test_window", 0, 0, 0, 0, 0, 0, 0, inst
, 0 );
264 ok_(__FILE__
,line
)( hwnd
!= NULL
, "Couldn't create window for class %s inst %p\n", name
, inst
);
265 ok_(__FILE__
,line
)( (HINSTANCE
)GetClassLongPtrA( hwnd
, GCLP_HMODULE
) == gcl_inst
,
266 "Wrong GCL instance %p/%p for class %s\n",
267 (HINSTANCE
)GetClassLongPtrA( hwnd
, GCLP_HMODULE
), gcl_inst
, name
);
268 ok_(__FILE__
,line
)( (HINSTANCE
)GetWindowLongPtrA( hwnd
, GWLP_HINSTANCE
) == inst
,
269 "Wrong GWL instance %p/%p for window %s\n",
270 (HINSTANCE
)GetWindowLongPtrA( hwnd
, GWLP_HINSTANCE
), inst
, name
);
271 ok_(__FILE__
,line
)(!UnregisterClassA(name
, inst
),
272 "UnregisterClassA should fail while exists a class window\n");
273 ok_(__FILE__
,line
)(GetLastError() == ERROR_CLASS_HAS_WINDOWS
,
274 "GetLastError() should be set to ERROR_CLASS_HAS_WINDOWS not %d\n", GetLastError());
277 #define check_instance(name,inst,info_inst,gcl_inst) check_instance_(__LINE__,name,inst,info_inst,gcl_inst)
282 HINSTANCE inst
, info_inst
, gcl_inst
;
285 static DWORD WINAPI
thread_proc(void *param
)
287 struct class_info
*class_info
= param
;
289 check_instance(class_info
->name
, class_info
->inst
, class_info
->info_inst
, class_info
->gcl_inst
);
294 static void check_thread_instance( const char *name
, HINSTANCE inst
, HINSTANCE info_inst
, HINSTANCE gcl_inst
)
298 struct class_info class_info
;
300 class_info
.name
= name
;
301 class_info
.inst
= inst
;
302 class_info
.info_inst
= info_inst
;
303 class_info
.gcl_inst
= gcl_inst
;
305 hThread
= CreateThread(NULL
, 0, thread_proc
, &class_info
, 0, &tid
);
306 ok(hThread
!= NULL
, "CreateThread failed, error %d\n", GetLastError());
307 ok(WaitForSingleObject(hThread
, INFINITE
) == WAIT_OBJECT_0
, "WaitForSingleObject failed\n");
308 CloseHandle(hThread
);
311 /* test various instance parameters */
312 static void test_instances(void)
317 const char *name
= "__test__";
318 HINSTANCE kernel32
= GetModuleHandleA("kernel32");
319 HINSTANCE user32
= GetModuleHandleA("user32");
320 HINSTANCE main_module
= GetModuleHandleA(NULL
);
321 HINSTANCE zero_instance
= 0;
325 memset( &cls
, 0, sizeof(cls
) );
326 cls
.style
= CS_HREDRAW
| CS_VREDRAW
;
327 cls
.lpfnWndProc
= ClassTest_WndProc
;
330 cls
.lpszClassName
= name
;
332 cls
.lpszMenuName
= "main_module";
333 cls
.hInstance
= main_module
;
335 ok( RegisterClassA( &cls
), "Failed to register local class for main module\n" );
336 check_class( main_module
, name
, "main_module" );
337 check_instance( name
, main_module
, main_module
, main_module
);
338 check_thread_instance( name
, main_module
, main_module
, main_module
);
340 cls
.lpszMenuName
= "kernel32";
341 cls
.hInstance
= kernel32
;
342 ok( RegisterClassA( &cls
), "Failed to register local class for kernel32\n" );
343 check_class( kernel32
, name
, "kernel32" );
344 check_class( main_module
, name
, "main_module" );
345 check_instance( name
, kernel32
, kernel32
, kernel32
);
346 check_thread_instance( name
, kernel32
, kernel32
, kernel32
);
347 ok( UnregisterClassA( name
, kernel32
), "Unregister failed for kernel32\n" );
349 ZeroMemory(&wcexA
, sizeof(wcexA
));
350 wcexA
.lpfnWndProc
= DefWindowProcA
;
351 wcexA
.lpszClassName
= "__classex_test__";
352 SetLastError(0xdeadbeef);
353 wcexA
.cbSize
= sizeof(wcexA
) - 1;
354 ok( ((RegisterClassExA( &wcexA
) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER
)),
355 "Succeeded with invalid number of cbSize bytes\n");
356 SetLastError(0xdeadbeef);
357 wcexA
.cbSize
= sizeof(wcexA
) + 1;
358 ok( ((RegisterClassExA( &wcexA
) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER
)),
359 "Succeeded with invalid number of cbSize bytes\n");
360 SetLastError(0xdeadbeef);
361 wcexA
.cbSize
= sizeof(wcexA
);
362 ok( RegisterClassExA( &wcexA
), "Failed with valid number of cbSize bytes\n");
363 wcexA
.cbSize
= 0xdeadbeef;
364 ok( GetClassInfoExA(main_module
, wcexA
.lpszClassName
, &wcexA
), "GetClassInfoEx failed\n");
365 ok( wcexA
.cbSize
== 0xdeadbeef, "GetClassInfoEx returned wrong cbSize value %d\n", wcexA
.cbSize
);
366 UnregisterClassA(wcexA
.lpszClassName
, main_module
);
368 /* Bug 2631 - Supplying an invalid number of bytes fails */
371 SetLastError(0xdeadbeef);
372 ok( ((RegisterClassA( &cls
) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER
)),
373 "Failed with invalid number of WndExtra bytes\n");
377 SetLastError(0xdeadbeef);
378 ok( ((RegisterClassA( &cls
) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER
)),
379 "Failed with invalid number of ClsExtra bytes\n");
383 SetLastError(0xdeadbeef);
384 ok( ((RegisterClassA( &cls
) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER
)),
385 "Failed with invalid number of ClsExtra and cbWndExtra bytes\n");
389 SetLastError(0xdeadbeef);
391 /* setting global flag doesn't change status of class */
392 hwnd
= CreateWindowExA( 0, name
, "test", 0, 0, 0, 0, 0, 0, 0, main_module
, 0 );
393 ok( hwnd
!= 0, "CreateWindow failed error %u\n", GetLastError());
394 SetClassLongA( hwnd
, GCL_STYLE
, CS_GLOBALCLASS
);
395 cls
.lpszMenuName
= "kernel32";
396 cls
.hInstance
= kernel32
;
397 ok( RegisterClassA( &cls
), "Failed to register local class for kernel32\n" );
398 check_class( kernel32
, name
, "kernel32" );
399 check_class( main_module
, name
, "main_module" );
400 check_instance( name
, kernel32
, kernel32
, kernel32
);
401 check_instance( name
, main_module
, main_module
, main_module
);
402 check_thread_instance( name
, kernel32
, kernel32
, kernel32
);
403 check_thread_instance( name
, main_module
, main_module
, main_module
);
404 ok( UnregisterClassA( name
, kernel32
), "Unregister failed for kernel32\n" );
406 /* changing the instance doesn't make it global */
407 SetClassLongPtrA( hwnd
, GCLP_HMODULE
, 0 );
408 ok( RegisterClassA( &cls
), "Failed to register local class for kernel32\n" );
409 check_class( kernel32
, name
, "kernel32" );
410 check_instance( name
, kernel32
, kernel32
, kernel32
);
411 check_thread_instance( name
, kernel32
, kernel32
, kernel32
);
412 ok( !GetClassInfoA( 0, name
, &wc
), "Class found with null instance\n" );
413 ok( UnregisterClassA( name
, kernel32
), "Unregister failed for kernel32\n" );
415 /* GetClassInfo with instance 0 finds user32 instance */
416 SetClassLongPtrA( hwnd
, GCLP_HMODULE
, (LONG_PTR
)user32
);
417 ok( RegisterClassA( &cls
), "Failed to register local class for kernel32\n" );
418 if (!GetClassInfoA( 0, name
, &wc
)) zero_instance
= user32
; /* instance 0 not supported on wow64 */
421 check_instance( name
, 0, 0, kernel32
);
422 check_thread_instance( name
, 0, 0, kernel32
);
424 check_class( kernel32
, name
, "kernel32" );
425 check_class( user32
, name
, "main_module" );
426 check_class( zero_instance
, name
, "main_module" );
427 check_instance( name
, kernel32
, kernel32
, kernel32
);
428 check_instance( name
, user32
, zero_instance
, user32
);
429 check_thread_instance( name
, kernel32
, kernel32
, kernel32
);
430 check_thread_instance( name
, user32
, zero_instance
, user32
);
431 ok( UnregisterClassA( name
, kernel32
), "Unregister failed for kernel32\n" );
433 SetClassLongPtrA( hwnd
, GCLP_HMODULE
, 0x12345678 );
434 ok( RegisterClassA( &cls
), "Failed to register local class for kernel32\n" );
435 check_class( kernel32
, name
, "kernel32" );
436 check_class( (HINSTANCE
)0x12345678, name
, "main_module" );
437 check_instance( name
, kernel32
, kernel32
, kernel32
);
438 check_instance( name
, (HINSTANCE
)0x12345678, (HINSTANCE
)0x12345678, (HINSTANCE
)0x12345678 );
439 check_thread_instance( name
, kernel32
, kernel32
, kernel32
);
440 check_thread_instance( name
, (HINSTANCE
)0x12345678, (HINSTANCE
)0x12345678, (HINSTANCE
)0x12345678 );
441 ok( !GetClassInfoA( 0, name
, &wc
), "Class found with null instance\n" );
443 /* creating a window with instance 0 uses the first class found */
444 cls
.hInstance
= (HINSTANCE
)0xdeadbeef;
445 cls
.lpszMenuName
= "deadbeef";
447 ok( RegisterClassA( &cls
), "Failed to register local class for deadbeef\n" );
448 hwnd2
= CreateWindowExA( 0, name
, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL
, 0 );
449 ok( GetClassLongPtrA( hwnd2
, GCLP_HMODULE
) == 0xdeadbeef,
450 "Didn't get deadbeef class for null instance\n" );
451 DestroyWindow( hwnd2
);
452 ok( UnregisterClassA( name
, (HINSTANCE
)0xdeadbeef ), "Unregister failed for deadbeef\n" );
454 hwnd2
= CreateWindowExA( 0, name
, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL
, 0 );
455 ok( (HINSTANCE
)GetClassLongPtrA( hwnd2
, GCLP_HMODULE
) == kernel32
,
456 "Didn't get kernel32 class for null instance\n" );
457 DestroyWindow( hwnd2
);
459 r
= GetClassNameA( hwnd
, buffer
, 4 );
460 ok( r
== 3, "expected 3, got %d\n", r
);
461 ok( !strcmp( buffer
, "__t"), "name wrong: %s\n", buffer
);
463 ok( UnregisterClassA( name
, kernel32
), "Unregister failed for kernel32\n" );
465 hwnd2
= CreateWindowExA( 0, name
, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL
, 0 );
466 ok( GetClassLongPtrA( hwnd2
, GCLP_HMODULE
) == 0x12345678,
467 "Didn't get 12345678 class for null instance\n" );
468 DestroyWindow( hwnd2
);
470 SetClassLongPtrA( hwnd
, GCLP_HMODULE
, (LONG_PTR
)main_module
);
471 DestroyWindow( hwnd
);
473 /* null handle means the same thing as main module */
474 cls
.lpszMenuName
= "null";
476 ok( !RegisterClassA( &cls
), "Succeeded registering local class for null instance\n" );
477 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS
, "Wrong error code %d\n", GetLastError() );
478 ok( UnregisterClassA( name
, main_module
), "Unregister failed for main module\n" );
480 ok( RegisterClassA( &cls
), "Failed to register local class for null instance\n" );
481 /* must be found with main module handle */
482 check_class( main_module
, name
, "null" );
483 check_instance( name
, main_module
, main_module
, main_module
);
484 check_thread_instance( name
, main_module
, main_module
, main_module
);
485 ok( !GetClassInfoA( 0, name
, &wc
), "Class found with null instance\n" );
486 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST
, "Wrong error code %d\n", GetLastError() );
487 ok( UnregisterClassA( name
, 0 ), "Unregister failed for null instance\n" );
489 /* registering for user32 always fails */
490 cls
.lpszMenuName
= "user32";
491 cls
.hInstance
= user32
;
492 ok( !RegisterClassA( &cls
), "Succeeded registering local class for user32\n" );
493 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "Wrong error code %d\n", GetLastError() );
494 cls
.style
|= CS_GLOBALCLASS
;
495 ok( !RegisterClassA( &cls
), "Succeeded registering global class for user32\n" );
496 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "Wrong error code %d\n", GetLastError() );
498 /* unregister is OK though */
499 cls
.hInstance
= main_module
;
500 ok( RegisterClassA( &cls
), "Failed to register global class for main module\n" );
501 ok( UnregisterClassA( name
, user32
), "Unregister failed for user32\n" );
503 /* instance doesn't matter for global class */
504 cls
.style
|= CS_GLOBALCLASS
;
505 cls
.lpszMenuName
= "main_module";
506 cls
.hInstance
= main_module
;
507 ok( RegisterClassA( &cls
), "Failed to register global class for main module\n" );
508 cls
.lpszMenuName
= "kernel32";
509 cls
.hInstance
= kernel32
;
510 ok( !RegisterClassA( &cls
), "Succeeded registering local class for kernel32\n" );
511 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS
, "Wrong error code %d\n", GetLastError() );
512 /* even if global flag is cleared */
513 hwnd
= CreateWindowExA( 0, name
, "test", 0, 0, 0, 0, 0, 0, 0, main_module
, 0 );
514 SetClassLongA( hwnd
, GCL_STYLE
, 0 );
515 ok( !RegisterClassA( &cls
), "Succeeded registering local class for kernel32\n" );
516 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS
, "Wrong error code %d\n", GetLastError() );
518 check_class( main_module
, name
, "main_module" );
519 check_class( kernel32
, name
, "main_module" );
520 check_class( 0, name
, "main_module" );
521 check_class( (HINSTANCE
)0x12345678, name
, "main_module" );
522 check_instance( name
, main_module
, main_module
, main_module
);
523 check_instance( name
, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, main_module
);
524 check_thread_instance( name
, main_module
, main_module
, main_module
);
525 check_thread_instance( name
, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, main_module
);
527 /* changing the instance for global class doesn't make much difference */
528 SetClassLongPtrA( hwnd
, GCLP_HMODULE
, 0xdeadbeef );
529 check_instance( name
, main_module
, main_module
, (HINSTANCE
)0xdeadbeef );
530 check_instance( name
, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef );
531 check_thread_instance( name
, main_module
, main_module
, (HINSTANCE
)0xdeadbeef );
532 check_thread_instance( name
, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef );
534 DestroyWindow( hwnd
);
535 ok( UnregisterClassA( name
, (HINSTANCE
)0x87654321 ), "Unregister failed for main module global\n" );
536 ok( !UnregisterClassA( name
, (HINSTANCE
)0x87654321 ), "Unregister succeeded the second time\n" );
537 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST
, "Wrong error code %d\n", GetLastError() );
539 cls
.hInstance
= (HINSTANCE
)0x12345678;
540 ok( RegisterClassA( &cls
), "Failed to register global class for dummy instance\n" );
541 check_instance( name
, main_module
, main_module
, (HINSTANCE
)0x12345678 );
542 check_instance( name
, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0x12345678 );
543 check_thread_instance( name
, main_module
, main_module
, (HINSTANCE
)0x12345678 );
544 check_thread_instance( name
, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0x12345678 );
545 ok( UnregisterClassA( name
, (HINSTANCE
)0x87654321 ), "Unregister failed for main module global\n" );
547 /* check system classes */
549 /* we cannot register a global class with the name of a system class */
550 cls
.style
|= CS_GLOBALCLASS
;
551 cls
.lpszMenuName
= "button_main_module";
552 cls
.lpszClassName
= "BUTTON";
553 cls
.hInstance
= main_module
;
554 ok( !RegisterClassA( &cls
), "Succeeded registering global button class for main module\n" );
555 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS
, "Wrong error code %d\n", GetLastError() );
556 cls
.hInstance
= kernel32
;
557 ok( !RegisterClassA( &cls
), "Succeeded registering global button class for kernel32\n" );
558 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS
, "Wrong error code %d\n", GetLastError() );
560 /* local class is OK however */
561 cls
.style
&= ~CS_GLOBALCLASS
;
562 cls
.lpszMenuName
= "button_main_module";
563 cls
.hInstance
= main_module
;
564 ok( RegisterClassA( &cls
), "Failed to register local button class for main module\n" );
565 check_class( main_module
, "BUTTON", "button_main_module" );
566 cls
.lpszMenuName
= "button_kernel32";
567 cls
.hInstance
= kernel32
;
568 ok( RegisterClassA( &cls
), "Failed to register local button class for kernel32\n" );
569 check_class( kernel32
, "BUTTON", "button_kernel32" );
570 check_class( main_module
, "BUTTON", "button_main_module" );
571 ok( UnregisterClassA( "BUTTON", kernel32
), "Unregister failed for kernel32 button\n" );
572 ok( UnregisterClassA( "BUTTON", main_module
), "Unregister failed for main module button\n" );
573 /* GetClassInfo sets instance to passed value for global classes */
574 check_instance( "BUTTON", 0, 0, user32
);
575 check_instance( "BUTTON", (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, user32
);
576 check_instance( "BUTTON", user32
, zero_instance
, user32
);
577 check_thread_instance( "BUTTON", 0, 0, user32
);
578 check_thread_instance( "BUTTON", (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, user32
);
579 check_thread_instance( "BUTTON", user32
, zero_instance
, user32
);
581 /* we can unregister system classes */
582 ok( GetClassInfoA( 0, "BUTTON", &wc
), "Button class not found with null instance\n" );
583 ok( GetClassInfoA( kernel32
, "BUTTON", &wc
), "Button class not found with kernel32\n" );
584 ok( UnregisterClassA( "BUTTON", (HINSTANCE
)0x12345678 ), "Failed to unregister button\n" );
585 ok( !UnregisterClassA( "BUTTON", (HINSTANCE
)0x87654321 ), "Unregistered button a second time\n" );
586 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST
, "Wrong error code %d\n", GetLastError() );
587 ok( !GetClassInfoA( 0, "BUTTON", &wc
), "Button still exists\n" );
588 /* last error not set reliably */
590 /* we can change the instance of a system class */
591 check_instance( "EDIT", (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, user32
);
592 check_thread_instance( "EDIT", (HINSTANCE
)0xdeadbeef, (HINSTANCE
)0xdeadbeef, user32
);
593 hwnd
= CreateWindowExA( 0, "EDIT", "test", 0, 0, 0, 0, 0, 0, 0, main_module
, 0 );
594 SetClassLongPtrA( hwnd
, GCLP_HMODULE
, 0xdeadbeef );
595 check_instance( "EDIT", (HINSTANCE
)0x12345678, (HINSTANCE
)0x12345678, (HINSTANCE
)0xdeadbeef );
596 check_thread_instance( "EDIT", (HINSTANCE
)0x12345678, (HINSTANCE
)0x12345678, (HINSTANCE
)0xdeadbeef );
600 static void test_builtinproc(void)
602 /* Edit behaves differently */
603 static const CHAR NORMAL_CLASSES
[][10] = {
610 "#32770", /* dialog */
612 static const int NUM_NORMAL_CLASSES
= (sizeof(NORMAL_CLASSES
)/sizeof(NORMAL_CLASSES
[0]));
613 static const char classA
[] = "deftest";
614 static const WCHAR classW
[] = {'d','e','f','t','e','s','t',0};
615 WCHAR unistring
[] = {0x142, 0x40e, 0x3b4, 0}; /* a string that would be destroyed by a W->A->W conversion */
616 WNDPROC pDefWindowProcA
, pDefWindowProcW
;
617 WNDPROC pNtdllDefWindowProcA
, pNtdllDefWindowProcW
;
619 WNDCLASSEXA cls
; /* the memory layout of WNDCLASSEXA and WNDCLASSEXW is the same */
625 pDefWindowProcA
= (void *)GetProcAddress(GetModuleHandleA("user32.dll"), "DefWindowProcA");
626 pDefWindowProcW
= (void *)GetProcAddress(GetModuleHandleA("user32.dll"), "DefWindowProcW");
627 pNtdllDefWindowProcA
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtdllDefWindowProc_A");
628 pNtdllDefWindowProcW
= (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtdllDefWindowProc_W");
630 /* On Vista+, the user32.dll export DefWindowProcA/W is forwarded to */
631 /* ntdll.NtdllDefWindowProc_A/W. However, the wndproc returned by */
632 /* GetClassLong/GetWindowLong points to an unexported user32 function */
633 if (pDefWindowProcA
== pNtdllDefWindowProcA
&&
634 pDefWindowProcW
== pNtdllDefWindowProcW
)
635 skip("user32.DefWindowProcX forwarded to ntdll.NtdllDefWindowProc_X\n");
638 for (i
= 0; i
< 4; i
++)
640 ZeroMemory(&cls
, sizeof(cls
));
641 cls
.cbSize
= sizeof(cls
);
642 cls
.hInstance
= GetModuleHandleA(NULL
);
643 cls
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
645 cls
.lpfnWndProc
= pDefWindowProcA
;
647 cls
.lpfnWndProc
= pDefWindowProcW
;
651 cls
.lpszClassName
= classA
;
652 atom
= RegisterClassExA(&cls
);
656 cls
.lpszClassName
= (LPCSTR
)classW
;
657 atom
= RegisterClassExW((WNDCLASSEXW
*)&cls
);
659 ok(atom
!= 0, "Couldn't register class, i=%d, %d\n", i
, GetLastError());
661 hwnd
= CreateWindowA(classA
, NULL
, 0, 0, 0, 100, 100, NULL
, NULL
, GetModuleHandleA(NULL
), NULL
);
662 ok(hwnd
!= NULL
, "Couldn't create window i=%d\n", i
);
664 ok(GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
) == (LONG_PTR
)pDefWindowProcA
, "Wrong ANSI wndproc: %p vs %p\n",
665 (void *)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), pDefWindowProcA
);
666 ok(GetClassLongPtrA(hwnd
, GCLP_WNDPROC
) == (ULONG_PTR
)pDefWindowProcA
, "Wrong ANSI wndproc: %p vs %p\n",
667 (void *)GetClassLongPtrA(hwnd
, GCLP_WNDPROC
), pDefWindowProcA
);
669 ok(GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == (LONG_PTR
)pDefWindowProcW
, "Wrong Unicode wndproc: %p vs %p\n",
670 (void *)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), pDefWindowProcW
);
671 ok(GetClassLongPtrW(hwnd
, GCLP_WNDPROC
) == (ULONG_PTR
)pDefWindowProcW
, "Wrong Unicode wndproc: %p vs %p\n",
672 (void *)GetClassLongPtrW(hwnd
, GCLP_WNDPROC
), pDefWindowProcW
);
675 UnregisterClassA((LPSTR
)(DWORD_PTR
)atom
, GetModuleHandleA(NULL
));
679 /* built-in winproc - window A/W type automatically detected */
680 ZeroMemory(&cls
, sizeof(cls
));
681 cls
.cbSize
= sizeof(cls
);
682 cls
.hInstance
= GetModuleHandleA(NULL
);
683 cls
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
684 cls
.lpszClassName
= classA
;
685 cls
.lpfnWndProc
= pDefWindowProcW
;
686 atom
= RegisterClassExA(&cls
);
688 hwnd
= CreateWindowExW(0, classW
, unistring
, WS_OVERLAPPEDWINDOW
,
689 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleW(NULL
), 0);
690 ok(IsWindowUnicode(hwnd
) ||
691 broken(!IsWindowUnicode(hwnd
)) /* Windows 8 and 10 */,
692 "Windows should be Unicode\n");
693 SendMessageW(hwnd
, WM_GETTEXT
, sizeof(buf
) / sizeof(buf
[0]), (LPARAM
)buf
);
694 if (IsWindowUnicode(hwnd
))
695 ok(memcmp(buf
, unistring
, sizeof(unistring
)) == 0, "WM_GETTEXT invalid return\n");
697 ok(memcmp(buf
, unistring
, sizeof(unistring
)) != 0, "WM_GETTEXT invalid return\n");
698 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)pDefWindowProcA
);
699 ok(IsWindowUnicode(hwnd
), "Windows should have remained Unicode\n");
700 if (GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == (LONG_PTR
)pDefWindowProcA
)
702 /* DefWindowProc isn't magic on wow64 */
703 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
)), "Ansi winproc is not a handle\n");
707 ok(GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
) == (LONG_PTR
)pDefWindowProcW
, "Invalid Unicode winproc\n");
708 ok(GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
) == (LONG_PTR
)pDefWindowProcA
, "Invalid Ansi winproc\n");
710 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)ClassTest_WndProc
);
711 ok(IsWindowUnicode(hwnd
) == FALSE
, "SetWindowLongPtrA should have switched window to ANSI\n");
714 UnregisterClassA((LPSTR
)(DWORD_PTR
)atom
, GetModuleHandleA(NULL
));
716 /* custom winproc - the same function can be used as both A and W*/
717 ZeroMemory(&cls
, sizeof(cls
));
718 cls
.cbSize
= sizeof(cls
);
719 cls
.hInstance
= GetModuleHandleA(NULL
);
720 cls
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
721 cls
.lpszClassName
= classA
;
722 cls
.lpfnWndProc
= ClassTest_WndProc2
;
723 atom
= RegisterClassExA(&cls
);
725 hwnd
= CreateWindowExW(0, classW
, NULL
, WS_OVERLAPPEDWINDOW
,
726 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, GetModuleHandleA(NULL
), 0);
727 ok(IsWindowUnicode(hwnd
) == FALSE
, "Window should be ANSI\n");
728 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)ClassTest_WndProc
);
729 ok(IsWindowUnicode(hwnd
), "SetWindowLongPtrW should have changed window to Unicode\n");
730 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)ClassTest_WndProc
);
731 ok(IsWindowUnicode(hwnd
) == FALSE
, "SetWindowLongPtrA should have changed window to ANSI\n");
734 UnregisterClassA((LPSTR
)(DWORD_PTR
)atom
, GetModuleHandleA(NULL
));
736 /* For most of the builtin controls both GetWindowLongPtrA and W returns a pointer that is executed directly
737 * by CallWindowProcA/W */
738 for (i
= 0; i
< NUM_NORMAL_CLASSES
; i
++)
740 WNDPROC procA
, procW
;
741 hwnd
= CreateWindowExA(0, NORMAL_CLASSES
[i
], classA
, WS_OVERLAPPEDWINDOW
, CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260,
742 NULL
, NULL
, NULL
, 0);
743 ok(hwnd
!= NULL
, "Couldn't create window of class %s\n", NORMAL_CLASSES
[i
]);
744 SetWindowTextA(hwnd
, classA
); /* ComboBox needs this */
745 procA
= (WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
);
746 procW
= (WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
);
747 ok(!IS_WNDPROC_HANDLE(procA
), "procA should not be a handle for %s (%p)\n", NORMAL_CLASSES
[i
], procA
);
748 ok(!IS_WNDPROC_HANDLE(procW
), "procW should not be a handle for %s (%p)\n", NORMAL_CLASSES
[i
], procW
);
749 CallWindowProcA(procA
, hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
750 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT A/A invalid return for class %s\n", NORMAL_CLASSES
[i
]);
751 CallWindowProcA(procW
, hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
752 ok(memcmp(buf
, classW
, sizeof(classW
)) == 0, "WM_GETTEXT A/W invalid return for class %s\n", NORMAL_CLASSES
[i
]);
753 CallWindowProcW(procA
, hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
754 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT W/A invalid return for class %s\n", NORMAL_CLASSES
[i
]);
755 CallWindowProcW(procW
, hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
756 ok(memcmp(buf
, classW
, sizeof(classW
)) == 0, "WM_GETTEXT W/W invalid return for class %s\n", NORMAL_CLASSES
[i
]);
758 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)ClassTest_WndProc
);
759 ok(IS_WNDPROC_HANDLE(oldproc
) == FALSE
, "Class %s shouldn't return a handle\n", NORMAL_CLASSES
[i
]);
760 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)oldproc
);
764 /* Edit controls are special - they return a wndproc handle when GetWindowLongPtr is called with a different A/W.
765 * On the other hand there is no W->A->W conversion so this control is treated specially. */
766 hwnd
= CreateWindowW(WC_EDITW
, unistring
, WS_OVERLAPPEDWINDOW
,
767 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, NULL
, 0);
768 /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
769 ok(IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd
, GCLP_WNDPROC
)) == FALSE
, "Edit control class should have a Unicode wndproc\n");
770 ok(IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd
, GCLP_WNDPROC
)) == FALSE
, "Edit control class should have a ANSI wndproc\n");
771 /* But GetWindowLongPtr returns only a handle for the ANSI one */
772 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
)), "Edit control should return a wndproc handle\n");
773 ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
)), "Edit control shouldn't return a W wndproc handle\n");
774 CallWindowProcW((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
775 ok(memcmp(buf
, unistring
, sizeof(unistring
)) == 0, "WM_GETTEXT invalid return\n");
776 CallWindowProcA((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
777 ok(memcmp(buf
, unistring
, sizeof(unistring
)) == 0, "WM_GETTEXT invalid return\n");
778 CallWindowProcW((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
779 ok(memcmp(buf
, unistring
, sizeof(unistring
)) == 0, "WM_GETTEXT invalid return\n");
781 SetWindowTextW(hwnd
, classW
);
782 CallWindowProcA((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
783 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
785 oldproc
= (WNDPROC
)SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)ClassTest_WndProc2
);
786 /* SetWindowLongPtr returns a wndproc handle - like GetWindowLongPtr */
787 ok(IS_WNDPROC_HANDLE(oldproc
), "Edit control should return a wndproc handle\n");
788 ok(IsWindowUnicode(hwnd
) == FALSE
, "SetWindowLongPtrA should have changed window to ANSI\n");
789 SetWindowTextA(hwnd
, classA
); /* Windows resets the title to WideStringToMultiByte(unistring) */
790 memset(buf
, 0, sizeof(buf
));
791 CallWindowProcA((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
792 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
793 CallWindowProcA((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
794 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
795 CallWindowProcW((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
796 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
798 CallWindowProcW((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
799 ok(memcmp(buf
, classW
, sizeof(classW
)) == 0, "WM_GETTEXT invalid return\n");
801 SetWindowLongPtrA(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)oldproc
);
805 hwnd
= CreateWindowA(WC_EDITA
, classA
, WS_OVERLAPPEDWINDOW
,
806 CW_USEDEFAULT
, CW_USEDEFAULT
, 680, 260, NULL
, NULL
, NULL
, 0);
808 /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
809 ok(!IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd
, GCLP_WNDPROC
)), "Edit control class should have a Unicode wndproc\n");
810 ok(!IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd
, GCLP_WNDPROC
)), "Edit control class should have a ANSI wndproc\n");
811 /* But GetWindowLongPtr returns only a handle for the Unicode one */
812 ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
)), "Edit control shouldn't return an A wndproc handle\n");
813 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
)), "Edit control should return a wndproc handle\n");
814 CallWindowProcA((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
815 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
816 CallWindowProcA((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
817 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
818 CallWindowProcW((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
819 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
821 CallWindowProcW((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
822 ok(memcmp(buf
, classW
, sizeof(classW
)) == 0, "WM_GETTEXT invalid return\n");
824 oldproc
= (WNDPROC
)SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)ClassTest_WndProc
);
825 SetWindowTextW(hwnd
, unistring
);
826 CallWindowProcW((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
827 ok(memcmp(buf
, unistring
, sizeof(unistring
)) == 0, "WM_GETTEXT invalid return\n");
828 CallWindowProcA((WNDPROC
)GetWindowLongPtrW(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
829 ok(memcmp(buf
, unistring
, sizeof(unistring
)) == 0, "WM_GETTEXT invalid return\n");
830 CallWindowProcW((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
831 ok(memcmp(buf
, unistring
, sizeof(unistring
)) == 0, "WM_GETTEXT invalid return\n");
833 SetWindowTextW(hwnd
, classW
);
834 CallWindowProcA((WNDPROC
)GetWindowLongPtrA(hwnd
, GWLP_WNDPROC
), hwnd
, WM_GETTEXT
, 120, (LPARAM
)buf
);
835 ok(memcmp(buf
, classA
, sizeof(classA
)) == 0, "WM_GETTEXT invalid return\n");
837 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (LONG_PTR
)oldproc
);
843 static LRESULT WINAPI
TestDlgProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
845 return DefWindowProcA(hWnd
, uMsg
, wParam
, lParam
);
848 static BOOL
RegisterTestDialog(HINSTANCE hInstance
)
853 ZeroMemory(&wcx
, sizeof(WNDCLASSEXA
));
854 wcx
.cbSize
= sizeof(wcx
);
855 wcx
.lpfnWndProc
= TestDlgProc
;
857 wcx
.cbWndExtra
= DLGWINDOWEXTRA
;
858 wcx
.hInstance
= hInstance
;
859 wcx
.hIcon
= LoadIconA(NULL
, (LPCSTR
)IDI_APPLICATION
);
860 wcx
.hCursor
= LoadCursorA(NULL
, (LPCSTR
)IDC_ARROW
);
861 wcx
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
862 wcx
.lpszClassName
= "TestDialog";
863 wcx
.lpszMenuName
= "TestDialog";
864 wcx
.hIconSm
= LoadImageA(hInstance
, (LPCSTR
)MAKEINTRESOURCE(5), IMAGE_ICON
,
865 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
868 atom
= RegisterClassExA(&wcx
);
869 ok(atom
!= 0, "RegisterClassEx returned 0\n");
874 /* test registering a dialog box created by using the CLASS directive in a
875 resource file, then test creating the dialog using CreateDialogParam. */
876 static void CreateDialogParamTest(HINSTANCE hInstance
)
880 if (RegisterTestDialog(hInstance
))
882 hWndMain
= CreateDialogParamA(hInstance
, "CLASS_TEST_DIALOG", NULL
, 0, 0);
883 ok(hWndMain
!= NULL
, "CreateDialogParam returned NULL\n");
884 ShowWindow(hWndMain
, SW_SHOW
);
885 DestroyWindow(hWndMain
);
896 {"#32770",30,30}, /* Dialog */
900 {"Edit",6,8}, /* Windows XP 64-bit returns 8 also to 32-bit applications */
904 static void test_extra_values(void)
907 for(i
=0; i
< sizeof(extra_values
)/sizeof(extra_values
[0]); i
++)
910 BOOL ret
= GetClassInfoExA(NULL
,extra_values
[i
].name
,&wcx
);
912 ok( ret
, "GetClassInfo (0) failed for global class %s\n", extra_values
[i
].name
);
914 ok(extra_values
[i
].value
== wcx
.cbWndExtra
|| broken(extra_values
[i
].badvalue
== wcx
.cbWndExtra
),
915 "expected %d, got %d\n", extra_values
[i
].value
, wcx
.cbWndExtra
);
919 static void test_GetClassInfo(void)
921 static const WCHAR staticW
[] = {'s','t','a','t','i','c',0};
926 SetLastError(0xdeadbeef);
927 ret
= GetClassInfoA(0, "static", &wc
);
928 ok(ret
, "GetClassInfoA() error %d\n", GetLastError());
930 if (0) { /* crashes under XP */
931 SetLastError(0xdeadbeef);
932 ret
= GetClassInfoA(0, "static", NULL
);
933 ok(ret
, "GetClassInfoA() error %d\n", GetLastError());
935 SetLastError(0xdeadbeef);
936 ret
= GetClassInfoW(0, staticW
, NULL
);
937 ok(ret
, "GetClassInfoW() error %d\n", GetLastError());
940 wcx
.cbSize
= sizeof(wcx
);
941 SetLastError(0xdeadbeef);
942 ret
= GetClassInfoExA(0, "static", &wcx
);
943 ok(ret
, "GetClassInfoExA() error %d\n", GetLastError());
945 SetLastError(0xdeadbeef);
946 ret
= GetClassInfoExA(0, "static", NULL
);
947 ok(!ret
, "GetClassInfoExA() should fail\n");
948 ok(GetLastError() == ERROR_NOACCESS
||
949 broken(GetLastError() == 0xdeadbeef), /* win9x */
950 "expected ERROR_NOACCESS, got %d\n", GetLastError());
952 SetLastError(0xdeadbeef);
953 ret
= GetClassInfoExW(0, staticW
, NULL
);
954 ok(!ret
, "GetClassInfoExW() should fail\n");
955 ok(GetLastError() == ERROR_NOACCESS
||
956 broken(GetLastError() == 0xdeadbeef) /* NT4 */ ||
957 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
), /* win9x */
958 "expected ERROR_NOACCESS, got %d\n", GetLastError());
961 wcx
.lpfnWndProc
= NULL
;
962 SetLastError(0xdeadbeef);
963 ret
= GetClassInfoExA(0, "static", &wcx
);
964 ok(ret
, "GetClassInfoExA() error %d\n", GetLastError());
965 ok(wcx
.cbSize
== 0, "expected 0, got %u\n", wcx
.cbSize
);
966 ok(wcx
.lpfnWndProc
!= NULL
, "got null proc\n");
968 wcx
.cbSize
= sizeof(wcx
) - 1;
969 wcx
.lpfnWndProc
= NULL
;
970 SetLastError(0xdeadbeef);
971 ret
= GetClassInfoExA(0, "static", &wcx
);
972 ok(ret
, "GetClassInfoExA() error %d\n", GetLastError());
973 ok(wcx
.cbSize
== sizeof(wcx
) - 1, "expected sizeof(wcx)-1, got %u\n", wcx
.cbSize
);
974 ok(wcx
.lpfnWndProc
!= NULL
, "got null proc\n");
976 wcx
.cbSize
= sizeof(wcx
) + 1;
977 wcx
.lpfnWndProc
= NULL
;
978 SetLastError(0xdeadbeef);
979 ret
= GetClassInfoExA(0, "static", &wcx
);
980 ok(ret
, "GetClassInfoExA() error %d\n", GetLastError());
981 ok(wcx
.cbSize
== sizeof(wcx
) + 1, "expected sizeof(wcx)+1, got %u\n", wcx
.cbSize
);
982 ok(wcx
.lpfnWndProc
!= NULL
, "got null proc\n");
985 static void test_icons(void)
987 WNDCLASSEXW wcex
, ret_wcex
;
988 WCHAR cls_name
[] = {'I','c','o','n','T','e','s','t','C','l','a','s','s',0};
990 HINSTANCE hinst
= GetModuleHandleW(0);
991 HICON hsmicon
, hsmallnew
;
994 memset(&wcex
, 0, sizeof wcex
);
995 wcex
.cbSize
= sizeof wcex
;
996 wcex
.lpfnWndProc
= ClassTest_WndProc
;
997 wcex
.hIcon
= LoadIconW(0, (LPCWSTR
)IDI_APPLICATION
);
998 wcex
.hInstance
= hinst
;
999 wcex
.lpszClassName
= cls_name
;
1000 ok(RegisterClassExW(&wcex
), "RegisterClassExW returned 0\n");
1001 hwnd
= CreateWindowExW(0, cls_name
, NULL
, WS_OVERLAPPEDWINDOW
,
1002 0, 0, 0, 0, NULL
, NULL
, hinst
, 0);
1003 ok(hwnd
!= NULL
, "Window was not created\n");
1005 ok(GetClassInfoExW(hinst
, cls_name
, &ret_wcex
), "Class info was not retrieved\n");
1006 ok(wcex
.hIcon
== ret_wcex
.hIcon
, "Icons don't match\n");
1007 ok(ret_wcex
.hIconSm
!= NULL
, "hIconSm should be non-zero handle\n");
1009 hsmicon
= (HICON
)GetClassLongPtrW(hwnd
, GCLP_HICONSM
);
1010 ok(hsmicon
!= NULL
, "GetClassLong should return non-zero handle\n");
1012 ok(SendMessageA(hwnd
, WM_GETICON
, ICON_BIG
, 0) == 0,
1013 "WM_GETICON with ICON_BIG should not return the class icon\n");
1014 ok(SendMessageA(hwnd
, WM_GETICON
, ICON_SMALL
, 0) == 0,
1015 "WM_GETICON with ICON_SMALL should not return the class icon\n");
1016 ok(SendMessageA(hwnd
, WM_GETICON
, ICON_SMALL2
, 0) == 0,
1017 "WM_GETICON with ICON_SMALL2 should not return the class icon\n");
1019 hsmallnew
= CopyImage(wcex
.hIcon
, IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
1020 GetSystemMetrics(SM_CYSMICON
), 0);
1021 ok(!SetClassLongPtrW(hwnd
, GCLP_HICONSM
, (LONG_PTR
)hsmallnew
),
1022 "Previous hIconSm should be zero\n");
1023 ok(hsmallnew
== (HICON
)GetClassLongPtrW(hwnd
, GCLP_HICONSM
),
1024 "Should return explicitly assigned small icon\n");
1025 ok(!GetIconInfo(hsmicon
, &icinf
), "Previous small icon should be destroyed\n");
1027 SetClassLongPtrW(hwnd
, GCLP_HICONSM
, 0);
1028 hsmicon
= (HICON
)GetClassLongPtrW(hwnd
, GCLP_HICONSM
);
1029 ok( hsmicon
!= NULL
, "GetClassLong should return non-zero handle\n");
1031 SetClassLongPtrW(hwnd
, GCLP_HICON
, 0);
1032 ok(!GetClassLongPtrW(hwnd
, GCLP_HICONSM
), "GetClassLong should return zero handle\n");
1034 SetClassLongPtrW(hwnd
, GCLP_HICON
, (LONG_PTR
)LoadIconW(NULL
, (LPCWSTR
)IDI_QUESTION
));
1035 hsmicon
= (HICON
)GetClassLongPtrW(hwnd
, GCLP_HICONSM
);
1036 ok(hsmicon
!= NULL
, "GetClassLong should return non-zero handle\n");
1037 UnregisterClassW(cls_name
, hinst
);
1038 ok(GetIconInfo(hsmicon
, &icinf
), "Icon should NOT be destroyed\n");
1040 DestroyIcon(hsmallnew
);
1041 DestroyWindow(hwnd
);
1044 static void test_comctl32_class( const char *name
)
1053 module
= GetModuleHandleA( "comctl32" );
1054 ok( !module
, "comctl32 already loaded\n" );
1055 ret
= GetClassInfoA( 0, name
, &wcA
);
1056 ok( ret
|| broken(!ret
) /* <= winxp */, "GetClassInfoA failed for %s\n", name
);
1058 MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) );
1059 ret
= GetClassInfoW( 0, nameW
, &wcW
);
1060 ok( ret
, "GetClassInfoW failed for %s\n", name
);
1061 module
= GetModuleHandleA( "comctl32" );
1062 ok( module
!= 0, "comctl32 not loaded\n" );
1063 FreeLibrary( module
);
1064 module
= GetModuleHandleA( "comctl32" );
1065 ok( !module
, "comctl32 still loaded\n" );
1066 hwnd
= CreateWindowA( name
, "test", WS_OVERLAPPEDWINDOW
, 0, 0, 10, 10, NULL
, NULL
, NULL
, 0 );
1067 ok( hwnd
!= 0, "failed to create window for %s\n", name
);
1068 module
= GetModuleHandleA( "comctl32" );
1069 ok( module
!= 0, "comctl32 not loaded\n" );
1072 /* verify that comctl32 classes are automatically loaded by user32 */
1073 static void test_comctl32_classes(void)
1075 char path_name
[MAX_PATH
];
1076 PROCESS_INFORMATION info
;
1077 STARTUPINFOA startup
;
1081 static const char *classes
[] =
1085 DATETIMEPICK_CLASSA
,
1104 winetest_get_mainargs( &argv
);
1105 for (i
= 0; i
< sizeof(classes
) / sizeof(classes
[0]); i
++)
1107 memset( &startup
, 0, sizeof(startup
) );
1108 startup
.cb
= sizeof( startup
);
1109 sprintf( path_name
, "%s class %s", argv
[0], classes
[i
] );
1110 ok( CreateProcessA( NULL
, path_name
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &startup
, &info
),
1111 "CreateProcess failed.\n" );
1112 winetest_wait_child_process( info
.hProcess
);
1113 CloseHandle( info
.hProcess
);
1114 CloseHandle( info
.hThread
);
1118 static void test_IME(void)
1120 static const WCHAR ime_classW
[] = {'I','M','E',0};
1122 char module_name
[MAX_PATH
], *ptr
;
1123 MEMORY_BASIC_INFORMATION mbi
;
1124 WNDCLASSW wnd_classw
;
1125 WNDCLASSA wnd_class
;
1129 if (!GetProcAddress(GetModuleHandleA("user32.dll"), "BroadcastSystemMessageExA"))
1131 win_skip("BroadcastSystemMessageExA not available, skipping IME class test\n");
1135 ok(GetModuleHandleA("imm32") != 0, "imm32.dll is not loaded\n");
1137 ret
= GetClassInfoA(NULL
, "IME", &wnd_class
);
1138 ok(ret
, "GetClassInfo failed: %d\n", GetLastError());
1140 size
= VirtualQuery(wnd_class
.lpfnWndProc
, &mbi
, sizeof(mbi
));
1141 ok(size
== sizeof(mbi
), "VirtualQuery returned %ld\n", size
);
1142 if (size
== sizeof(mbi
)) {
1143 size
= GetModuleFileNameA(mbi
.AllocationBase
, module_name
, sizeof(module_name
));
1144 ok(size
, "GetModuleFileName failed\n");
1145 for (ptr
= module_name
+size
-1; ptr
> module_name
; ptr
--)
1146 if (*ptr
== '\\' || *ptr
== '/') break;
1147 if (*ptr
== '\\' || *ptr
=='/') ptr
++;
1148 ok(!lstrcmpiA(ptr
, "user32.dll") || !lstrcmpiA(ptr
, "ntdll.dll"), "IME window proc implemented in %s\n", ptr
);
1151 ret
= GetClassInfoW(NULL
, ime_classW
, &wnd_classw
);
1152 ok(ret
, "GetClassInfo failed: %d\n", GetLastError());
1154 size
= VirtualQuery(wnd_classw
.lpfnWndProc
, &mbi
, sizeof(mbi
));
1155 ok(size
== sizeof(mbi
), "VirtualQuery returned %ld\n", size
);
1156 size
= GetModuleFileNameA(mbi
.AllocationBase
, module_name
, sizeof(module_name
));
1157 ok(size
, "GetModuleFileName failed\n");
1158 for (ptr
= module_name
+size
-1; ptr
> module_name
; ptr
--)
1159 if (*ptr
== '\\' || *ptr
== '/') break;
1160 if (*ptr
== '\\' || *ptr
=='/') ptr
++;
1161 ok(!lstrcmpiA(ptr
, "user32.dll") || !lstrcmpiA(ptr
, "ntdll.dll"), "IME window proc implemented in %s\n", ptr
);
1167 HANDLE hInstance
= GetModuleHandleA( NULL
);
1168 int argc
= winetest_get_mainargs( &argv
);
1172 test_comctl32_class( argv
[2] );
1177 test_GetClassInfo();
1178 test_extra_values();
1180 if (!GetModuleHandleW(0))
1182 trace("Class test is incompatible with Win9x implementation, skipping\n");
1186 ClassTest(hInstance
,FALSE
);
1187 ClassTest(hInstance
,TRUE
);
1188 CreateDialogParamTest(hInstance
);
1192 test_comctl32_classes();
1194 /* this test unregisters the Button class so it should be executed at the end */