user32: Automatically load the module implementing redirected class.
[wine.git] / dlls / user32 / tests / class.c
blobae885dbac9d815f40b2009d575462a1db03fab10
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
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdio.h>
28 #include "wine/test.h"
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winnls.h"
32 #include "winreg.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "commctrl.h"
37 #define NUMCLASSWORDS 4
39 #define IS_WNDPROC_HANDLE(x) (((ULONG_PTR)(x) >> 16) == (~0u >> 16))
41 #ifdef __i386__
42 #define ARCH "x86"
43 #elif defined __x86_64__
44 #define ARCH "amd64"
45 #elif defined __arm__
46 #define ARCH "arm"
47 #elif defined __aarch64__
48 #define ARCH "arm64"
49 #else
50 #define ARCH "none"
51 #endif
53 static const char comctl32_manifest[] =
54 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
55 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">\n"
56 " <assemblyIdentity\n"
57 " type=\"win32\"\n"
58 " name=\"Wine.User32.Tests\"\n"
59 " version=\"1.0.0.0\"\n"
60 " processorArchitecture=\"" ARCH "\"\n"
61 " />\n"
62 "<description>Wine comctl32 test suite</description>\n"
63 "<dependency>\n"
64 " <dependentAssembly>\n"
65 " <assemblyIdentity\n"
66 " type=\"win32\"\n"
67 " name=\"microsoft.windows.common-controls\"\n"
68 " version=\"6.0.0.0\"\n"
69 " processorArchitecture=\"" ARCH "\"\n"
70 " publicKeyToken=\"6595b64144ccf1df\"\n"
71 " language=\"*\"\n"
72 " />\n"
73 "</dependentAssembly>\n"
74 "</dependency>\n"
75 "</assembly>\n";
77 static LRESULT WINAPI ClassTest_WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
79 if (msg == WM_NCCREATE) return 1;
80 return DefWindowProcW (hWnd, msg, wParam, lParam);
83 static LRESULT WINAPI ClassTest_WndProc2 (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
85 if (msg == WM_NCCREATE) return 1;
86 return DefWindowProcA (hWnd, msg, wParam, lParam);
89 /***********************************************************************
91 static void ClassTest(HINSTANCE hInstance, BOOL global)
93 WNDCLASSW cls, wc;
94 static const WCHAR className[] = {'T','e','s','t','C','l','a','s','s',0};
95 static const WCHAR winName[] = {'W','i','n','C','l','a','s','s','T','e','s','t',0};
96 ATOM test_atom;
97 HWND hTestWnd;
98 LONG i;
99 WCHAR str[20];
100 ATOM classatom;
102 cls.style = CS_HREDRAW | CS_VREDRAW | (global?CS_GLOBALCLASS:0);
103 cls.lpfnWndProc = ClassTest_WndProc;
104 cls.cbClsExtra = NUMCLASSWORDS*sizeof(DWORD);
105 cls.cbWndExtra = 12;
106 cls.hInstance = hInstance;
107 cls.hIcon = LoadIconW (0, (LPWSTR)IDI_APPLICATION);
108 cls.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
109 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
110 cls.lpszMenuName = 0;
111 cls.lpszClassName = className;
113 classatom=RegisterClassW(&cls);
114 if (!classatom && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
115 return;
116 ok(classatom, "failed to register class\n");
118 ok(!RegisterClassW (&cls),
119 "RegisterClass of the same class should fail for the second time\n");
121 /* Setup windows */
122 hTestWnd = CreateWindowW (className, winName,
123 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
124 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
125 0, hInstance, 0);
127 ok(hTestWnd!=0, "Failed to create window\n");
129 /* test initial values of valid classwords */
130 for(i=0; i<NUMCLASSWORDS; i++)
132 SetLastError(0);
133 ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
134 "GetClassLongW initial value nonzero!\n");
135 ok(!GetLastError(),
136 "GetClassLongW failed!\n");
139 if (0)
142 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
143 * does not fail on Win 98, though MSDN says it should
145 SetLastError(0);
146 GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
147 ok(GetLastError(),
148 "GetClassLongW() with invalid offset did not fail\n");
151 /* set values of valid class words */
152 for(i=0; i<NUMCLASSWORDS; i++)
154 SetLastError(0);
155 ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
156 "GetClassLongW(%d) initial value nonzero!\n",i);
157 ok(!GetLastError(),
158 "SetClassLongW(%d) failed!\n",i);
161 /* test values of valid classwords that we set */
162 for(i=0; i<NUMCLASSWORDS; i++)
164 SetLastError(0);
165 ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
166 "GetClassLongW value doesn't match what was set!\n");
167 ok(!GetLastError(),
168 "GetClassLongW failed!\n");
171 /* check GetClassName */
172 i = GetClassNameW(hTestWnd, str, sizeof(str)/sizeof(str[0]));
173 ok(i == lstrlenW(className),
174 "GetClassName returned incorrect length\n");
175 ok(!lstrcmpW(className,str),
176 "GetClassName returned incorrect name for this window's class\n");
178 /* check GetClassInfo with our hInstance */
179 if((test_atom = GetClassInfoW(hInstance, str, &wc)))
181 ok(test_atom == classatom,
182 "class atom did not match\n");
183 ok(wc.cbClsExtra == cls.cbClsExtra,
184 "cbClsExtra did not match\n");
185 ok(wc.cbWndExtra == cls.cbWndExtra,
186 "cbWndExtra did not match\n");
187 ok(wc.hbrBackground == cls.hbrBackground,
188 "hbrBackground did not match\n");
189 ok(wc.hCursor== cls.hCursor,
190 "hCursor did not match\n");
191 ok(wc.hInstance== cls.hInstance,
192 "hInstance did not match\n");
194 else
195 ok(FALSE,"GetClassInfo (hinstance) failed!\n");
197 /* check GetClassInfo with zero hInstance */
198 if(global)
200 if((test_atom = GetClassInfoW(0, str, &wc)))
202 ok(test_atom == classatom,
203 "class atom did not match %x != %x\n", test_atom, classatom);
204 ok(wc.cbClsExtra == cls.cbClsExtra,
205 "cbClsExtra did not match %x!=%x\n",wc.cbClsExtra,cls.cbClsExtra);
206 ok(wc.cbWndExtra == cls.cbWndExtra,
207 "cbWndExtra did not match %x!=%x\n",wc.cbWndExtra,cls.cbWndExtra);
208 ok(wc.hbrBackground == cls.hbrBackground,
209 "hbrBackground did not match %p!=%p\n",wc.hbrBackground,cls.hbrBackground);
210 ok(wc.hCursor== cls.hCursor,
211 "hCursor did not match %p!=%p\n",wc.hCursor,cls.hCursor);
212 ok(!wc.hInstance,
213 "hInstance not zero for global class %p\n",wc.hInstance);
215 else
216 ok(FALSE,"GetClassInfo (0) failed for global class!\n");
218 else
220 ok(!GetClassInfoW(0, str, &wc),
221 "GetClassInfo (0) succeeded for local class!\n");
224 ok(!UnregisterClassW(className, hInstance),
225 "Unregister class succeeded with window existing\n");
227 ok(DestroyWindow(hTestWnd),
228 "DestroyWindow() failed!\n");
230 ok(UnregisterClassW(className, hInstance),
231 "UnregisterClass() failed\n");
233 return;
236 static void check_style( const char *name, int must_exist, UINT style, UINT ignore )
238 WNDCLASSA wc;
240 if (GetClassInfoA( 0, name, &wc ))
242 ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n",
243 name, ~wc.style & style, wc.style, style );
244 ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n",
245 name, wc.style & ~style, wc.style, style );
247 else
248 ok( !must_exist, "System class %s does not exist\n", name );
251 /* test styles of system classes */
252 static void test_styles(void)
254 /* check style bits */
255 check_style( "Button", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
256 check_style( "ComboBox", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
257 check_style( "Edit", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
258 check_style( "ListBox", 1, CS_PARENTDC | CS_DBLCLKS, CS_PARENTDC /*FIXME*/ );
259 check_style( "MDIClient", 1, 0, 0 );
260 check_style( "ScrollBar", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
261 check_style( "Static", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
262 check_style( "ComboLBox", 1, CS_SAVEBITS | CS_DBLCLKS, 0 );
263 check_style( "DDEMLEvent", 0, 0, 0 );
264 check_style( "Message", 0, 0, 0 );
265 check_style( "#32768", 1, CS_DROPSHADOW | CS_SAVEBITS | CS_DBLCLKS, CS_DROPSHADOW ); /* menu */
266 check_style( "#32769", 1, CS_DBLCLKS, 0 ); /* desktop */
267 check_style( "#32770", 1, CS_SAVEBITS | CS_DBLCLKS, 0 ); /* dialog */
268 todo_wine { check_style( "#32771", 1, CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW, 0 ); } /* task switch */
269 check_style( "#32772", 1, 0, 0 ); /* icon title */
272 static void check_class_(int line, HINSTANCE inst, const char *name, const char *menu_name)
274 WNDCLASSA wc;
275 UINT atom = GetClassInfoA(inst,name,&wc);
276 ok_(__FILE__,line)( atom, "Class %s %p not found\n", name, inst );
277 if (atom)
279 if (wc.lpszMenuName && menu_name)
280 ok_(__FILE__,line)( !strcmp( menu_name, wc.lpszMenuName ),
281 "Wrong name %s/%s for class %s %p\n",
282 wc.lpszMenuName, menu_name, name, inst );
283 else
284 ok_(__FILE__,line)( !menu_name == !wc.lpszMenuName, "Wrong name %p/%p for class %s %p\n",
285 wc.lpszMenuName, menu_name, name, inst );
288 #define check_class(inst,name,menu) check_class_(__LINE__,inst,name,menu)
290 static void check_instance_( int line, const char *name, HINSTANCE inst,
291 HINSTANCE info_inst, HINSTANCE gcl_inst )
293 WNDCLASSA wc;
294 HWND hwnd;
296 ok_(__FILE__,line)( GetClassInfoA( inst, name, &wc ), "Couldn't find class %s inst %p\n", name, inst );
297 ok_(__FILE__,line)( wc.hInstance == info_inst, "Wrong info instance %p/%p for class %s\n",
298 wc.hInstance, info_inst, name );
299 hwnd = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, inst, 0 );
300 ok_(__FILE__,line)( hwnd != NULL, "Couldn't create window for class %s inst %p\n", name, inst );
301 ok_(__FILE__,line)( (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ) == gcl_inst,
302 "Wrong GCL instance %p/%p for class %s\n",
303 (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ), gcl_inst, name );
304 ok_(__FILE__,line)( (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ) == inst,
305 "Wrong GWL instance %p/%p for window %s\n",
306 (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), inst, name );
307 ok_(__FILE__,line)(!UnregisterClassA(name, inst),
308 "UnregisterClassA should fail while exists a class window\n");
309 ok_(__FILE__,line)(GetLastError() == ERROR_CLASS_HAS_WINDOWS,
310 "GetLastError() should be set to ERROR_CLASS_HAS_WINDOWS not %d\n", GetLastError());
311 DestroyWindow(hwnd);
313 #define check_instance(name,inst,info_inst,gcl_inst) check_instance_(__LINE__,name,inst,info_inst,gcl_inst)
315 struct class_info
317 const char *name;
318 HINSTANCE inst, info_inst, gcl_inst;
321 static DWORD WINAPI thread_proc(void *param)
323 struct class_info *class_info = param;
325 check_instance(class_info->name, class_info->inst, class_info->info_inst, class_info->gcl_inst);
327 return 0;
330 static void check_thread_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
332 HANDLE hThread;
333 DWORD tid;
334 struct class_info class_info;
336 class_info.name = name;
337 class_info.inst = inst;
338 class_info.info_inst = info_inst;
339 class_info.gcl_inst = gcl_inst;
341 hThread = CreateThread(NULL, 0, thread_proc, &class_info, 0, &tid);
342 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
343 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
344 CloseHandle(hThread);
347 /* test various instance parameters */
348 static void test_instances(void)
350 WNDCLASSA cls, wc;
351 WNDCLASSEXA wcexA;
352 HWND hwnd, hwnd2;
353 const char *name = "__test__";
354 HINSTANCE kernel32 = GetModuleHandleA("kernel32");
355 HINSTANCE user32 = GetModuleHandleA("user32");
356 HINSTANCE main_module = GetModuleHandleA(NULL);
357 HINSTANCE zero_instance = 0;
358 DWORD r;
359 char buffer[0x10];
361 memset( &cls, 0, sizeof(cls) );
362 cls.style = CS_HREDRAW | CS_VREDRAW;
363 cls.lpfnWndProc = ClassTest_WndProc;
364 cls.cbClsExtra = 0;
365 cls.cbWndExtra = 0;
366 cls.lpszClassName = name;
368 cls.lpszMenuName = "main_module";
369 cls.hInstance = main_module;
371 ok( RegisterClassA( &cls ), "Failed to register local class for main module\n" );
372 check_class( main_module, name, "main_module" );
373 check_instance( name, main_module, main_module, main_module );
374 check_thread_instance( name, main_module, main_module, main_module );
376 cls.lpszMenuName = "kernel32";
377 cls.hInstance = kernel32;
378 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
379 check_class( kernel32, name, "kernel32" );
380 check_class( main_module, name, "main_module" );
381 check_instance( name, kernel32, kernel32, kernel32 );
382 check_thread_instance( name, kernel32, kernel32, kernel32 );
383 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
385 ZeroMemory(&wcexA, sizeof(wcexA));
386 wcexA.lpfnWndProc = DefWindowProcA;
387 wcexA.lpszClassName = "__classex_test__";
388 SetLastError(0xdeadbeef);
389 wcexA.cbSize = sizeof(wcexA) - 1;
390 ok( ((RegisterClassExA( &wcexA ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
391 "Succeeded with invalid number of cbSize bytes\n");
392 SetLastError(0xdeadbeef);
393 wcexA.cbSize = sizeof(wcexA) + 1;
394 ok( ((RegisterClassExA( &wcexA ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
395 "Succeeded with invalid number of cbSize bytes\n");
396 SetLastError(0xdeadbeef);
397 wcexA.cbSize = sizeof(wcexA);
398 ok( RegisterClassExA( &wcexA ), "Failed with valid number of cbSize bytes\n");
399 wcexA.cbSize = 0xdeadbeef;
400 ok( GetClassInfoExA(main_module, wcexA.lpszClassName, &wcexA), "GetClassInfoEx failed\n");
401 ok( wcexA.cbSize == 0xdeadbeef, "GetClassInfoEx returned wrong cbSize value %d\n", wcexA.cbSize);
402 UnregisterClassA(wcexA.lpszClassName, main_module);
404 /* Bug 2631 - Supplying an invalid number of bytes fails */
405 cls.cbClsExtra = 0;
406 cls.cbWndExtra = -1;
407 SetLastError(0xdeadbeef);
408 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
409 "Failed with invalid number of WndExtra bytes\n");
411 cls.cbClsExtra = -1;
412 cls.cbWndExtra = 0;
413 SetLastError(0xdeadbeef);
414 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
415 "Failed with invalid number of ClsExtra bytes\n");
417 cls.cbClsExtra = -1;
418 cls.cbWndExtra = -1;
419 SetLastError(0xdeadbeef);
420 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
421 "Failed with invalid number of ClsExtra and cbWndExtra bytes\n");
423 cls.cbClsExtra = 0;
424 cls.cbWndExtra = 0;
425 SetLastError(0xdeadbeef);
427 /* setting global flag doesn't change status of class */
428 hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
429 ok( hwnd != 0, "CreateWindow failed error %u\n", GetLastError());
430 SetClassLongA( hwnd, GCL_STYLE, CS_GLOBALCLASS );
431 cls.lpszMenuName = "kernel32";
432 cls.hInstance = kernel32;
433 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
434 check_class( kernel32, name, "kernel32" );
435 check_class( main_module, name, "main_module" );
436 check_instance( name, kernel32, kernel32, kernel32 );
437 check_instance( name, main_module, main_module, main_module );
438 check_thread_instance( name, kernel32, kernel32, kernel32 );
439 check_thread_instance( name, main_module, main_module, main_module );
440 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
442 /* changing the instance doesn't make it global */
443 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0 );
444 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
445 check_class( kernel32, name, "kernel32" );
446 check_instance( name, kernel32, kernel32, kernel32 );
447 check_thread_instance( name, kernel32, kernel32, kernel32 );
448 ok( !GetClassInfoA( 0, name, &wc ), "Class found with null instance\n" );
449 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
451 /* GetClassInfo with instance 0 finds user32 instance */
452 SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)user32 );
453 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
454 if (!GetClassInfoA( 0, name, &wc )) zero_instance = user32; /* instance 0 not supported on wow64 */
455 else
457 check_instance( name, 0, 0, kernel32 );
458 check_thread_instance( name, 0, 0, kernel32 );
460 check_class( kernel32, name, "kernel32" );
461 check_class( user32, name, "main_module" );
462 check_class( zero_instance, name, "main_module" );
463 check_instance( name, kernel32, kernel32, kernel32 );
464 check_instance( name, user32, zero_instance, user32 );
465 check_thread_instance( name, kernel32, kernel32, kernel32 );
466 check_thread_instance( name, user32, zero_instance, user32 );
467 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
469 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0x12345678 );
470 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
471 check_class( kernel32, name, "kernel32" );
472 check_class( (HINSTANCE)0x12345678, name, "main_module" );
473 check_instance( name, kernel32, kernel32, kernel32 );
474 check_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
475 check_thread_instance( name, kernel32, kernel32, kernel32 );
476 check_thread_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
477 ok( !GetClassInfoA( 0, name, &wc ), "Class found with null instance\n" );
479 /* creating a window with instance 0 uses the first class found */
480 cls.hInstance = (HINSTANCE)0xdeadbeef;
481 cls.lpszMenuName = "deadbeef";
482 cls.style = 3;
483 ok( RegisterClassA( &cls ), "Failed to register local class for deadbeef\n" );
484 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
485 ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0xdeadbeef,
486 "Didn't get deadbeef class for null instance\n" );
487 DestroyWindow( hwnd2 );
488 ok( UnregisterClassA( name, (HINSTANCE)0xdeadbeef ), "Unregister failed for deadbeef\n" );
490 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
491 ok( (HINSTANCE)GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == kernel32,
492 "Didn't get kernel32 class for null instance\n" );
493 DestroyWindow( hwnd2 );
495 r = GetClassNameA( hwnd, buffer, 4 );
496 ok( r == 3, "expected 3, got %d\n", r );
497 ok( !strcmp( buffer, "__t"), "name wrong: %s\n", buffer );
499 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
501 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
502 ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0x12345678,
503 "Didn't get 12345678 class for null instance\n" );
504 DestroyWindow( hwnd2 );
506 SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)main_module );
507 DestroyWindow( hwnd );
509 /* null handle means the same thing as main module */
510 cls.lpszMenuName = "null";
511 cls.hInstance = 0;
512 ok( !RegisterClassA( &cls ), "Succeeded registering local class for null instance\n" );
513 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
514 ok( UnregisterClassA( name, main_module ), "Unregister failed for main module\n" );
516 ok( RegisterClassA( &cls ), "Failed to register local class for null instance\n" );
517 /* must be found with main module handle */
518 check_class( main_module, name, "null" );
519 check_instance( name, main_module, main_module, main_module );
520 check_thread_instance( name, main_module, main_module, main_module );
521 ok( !GetClassInfoA( 0, name, &wc ), "Class found with null instance\n" );
522 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
523 ok( UnregisterClassA( name, 0 ), "Unregister failed for null instance\n" );
525 /* registering for user32 always fails */
526 cls.lpszMenuName = "user32";
527 cls.hInstance = user32;
528 ok( !RegisterClassA( &cls ), "Succeeded registering local class for user32\n" );
529 ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
530 cls.style |= CS_GLOBALCLASS;
531 ok( !RegisterClassA( &cls ), "Succeeded registering global class for user32\n" );
532 ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
534 /* unregister is OK though */
535 cls.hInstance = main_module;
536 ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
537 ok( UnregisterClassA( name, user32 ), "Unregister failed for user32\n" );
539 /* instance doesn't matter for global class */
540 cls.style |= CS_GLOBALCLASS;
541 cls.lpszMenuName = "main_module";
542 cls.hInstance = main_module;
543 ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
544 cls.lpszMenuName = "kernel32";
545 cls.hInstance = kernel32;
546 ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
547 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
548 /* even if global flag is cleared */
549 hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
550 SetClassLongA( hwnd, GCL_STYLE, 0 );
551 ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
552 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
554 check_class( main_module, name, "main_module" );
555 check_class( kernel32, name, "main_module" );
556 check_class( 0, name, "main_module" );
557 check_class( (HINSTANCE)0x12345678, name, "main_module" );
558 check_instance( name, main_module, main_module, main_module );
559 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
560 check_thread_instance( name, main_module, main_module, main_module );
561 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
563 /* changing the instance for global class doesn't make much difference */
564 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
565 check_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
566 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
567 check_thread_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
568 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
570 DestroyWindow( hwnd );
571 ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
572 ok( !UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister succeeded the second time\n" );
573 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
575 cls.hInstance = (HINSTANCE)0x12345678;
576 ok( RegisterClassA( &cls ), "Failed to register global class for dummy instance\n" );
577 check_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
578 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
579 check_thread_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
580 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
581 ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
583 /* check system classes */
585 /* we cannot register a global class with the name of a system class */
586 cls.style |= CS_GLOBALCLASS;
587 cls.lpszMenuName = "button_main_module";
588 cls.lpszClassName = "BUTTON";
589 cls.hInstance = main_module;
590 ok( !RegisterClassA( &cls ), "Succeeded registering global button class for main module\n" );
591 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
592 cls.hInstance = kernel32;
593 ok( !RegisterClassA( &cls ), "Succeeded registering global button class for kernel32\n" );
594 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
596 /* local class is OK however */
597 cls.style &= ~CS_GLOBALCLASS;
598 cls.lpszMenuName = "button_main_module";
599 cls.hInstance = main_module;
600 ok( RegisterClassA( &cls ), "Failed to register local button class for main module\n" );
601 check_class( main_module, "BUTTON", "button_main_module" );
602 cls.lpszMenuName = "button_kernel32";
603 cls.hInstance = kernel32;
604 ok( RegisterClassA( &cls ), "Failed to register local button class for kernel32\n" );
605 check_class( kernel32, "BUTTON", "button_kernel32" );
606 check_class( main_module, "BUTTON", "button_main_module" );
607 ok( UnregisterClassA( "BUTTON", kernel32 ), "Unregister failed for kernel32 button\n" );
608 ok( UnregisterClassA( "BUTTON", main_module ), "Unregister failed for main module button\n" );
609 /* GetClassInfo sets instance to passed value for global classes */
610 check_instance( "BUTTON", 0, 0, user32 );
611 check_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
612 check_instance( "BUTTON", user32, zero_instance, user32 );
613 check_thread_instance( "BUTTON", 0, 0, user32 );
614 check_thread_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
615 check_thread_instance( "BUTTON", user32, zero_instance, user32 );
617 /* we can unregister system classes */
618 ok( GetClassInfoA( 0, "BUTTON", &wc ), "Button class not found with null instance\n" );
619 ok( GetClassInfoA( kernel32, "BUTTON", &wc ), "Button class not found with kernel32\n" );
620 ok( UnregisterClassA( "BUTTON", (HINSTANCE)0x12345678 ), "Failed to unregister button\n" );
621 ok( !UnregisterClassA( "BUTTON", (HINSTANCE)0x87654321 ), "Unregistered button a second time\n" );
622 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
623 ok( !GetClassInfoA( 0, "BUTTON", &wc ), "Button still exists\n" );
624 /* last error not set reliably */
626 /* we can change the instance of a system class */
627 check_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
628 check_thread_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
629 hwnd = CreateWindowExA( 0, "EDIT", "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
630 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
631 check_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
632 check_thread_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
633 DestroyWindow(hwnd);
636 static void test_builtinproc(void)
638 /* Edit behaves differently */
639 static const CHAR NORMAL_CLASSES[][10] = {
640 "Button",
641 "Static",
642 "ComboBox",
643 "ComboLBox",
644 "ListBox",
645 "ScrollBar",
646 "#32770", /* dialog */
648 static const int NUM_NORMAL_CLASSES = (sizeof(NORMAL_CLASSES)/sizeof(NORMAL_CLASSES[0]));
649 static const char classA[] = "deftest";
650 static const WCHAR classW[] = {'d','e','f','t','e','s','t',0};
651 WCHAR unistring[] = {0x142, 0x40e, 0x3b4, 0}; /* a string that would be destroyed by a W->A->W conversion */
652 WNDPROC pDefWindowProcA, pDefWindowProcW;
653 WNDPROC pNtdllDefWindowProcA, pNtdllDefWindowProcW;
654 WNDPROC oldproc;
655 WNDCLASSEXA cls; /* the memory layout of WNDCLASSEXA and WNDCLASSEXW is the same */
656 WCHAR buf[128];
657 ATOM atom;
658 HWND hwnd;
659 int i;
661 pDefWindowProcA = (void *)GetProcAddress(GetModuleHandleA("user32.dll"), "DefWindowProcA");
662 pDefWindowProcW = (void *)GetProcAddress(GetModuleHandleA("user32.dll"), "DefWindowProcW");
663 pNtdllDefWindowProcA = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtdllDefWindowProc_A");
664 pNtdllDefWindowProcW = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtdllDefWindowProc_W");
666 /* On Vista+, the user32.dll export DefWindowProcA/W is forwarded to */
667 /* ntdll.NtdllDefWindowProc_A/W. However, the wndproc returned by */
668 /* GetClassLong/GetWindowLong points to an unexported user32 function */
669 if (pDefWindowProcA == pNtdllDefWindowProcA &&
670 pDefWindowProcW == pNtdllDefWindowProcW)
671 skip("user32.DefWindowProcX forwarded to ntdll.NtdllDefWindowProc_X\n");
672 else
674 for (i = 0; i < 4; i++)
676 ZeroMemory(&cls, sizeof(cls));
677 cls.cbSize = sizeof(cls);
678 cls.hInstance = GetModuleHandleA(NULL);
679 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
680 if (i & 1)
681 cls.lpfnWndProc = pDefWindowProcA;
682 else
683 cls.lpfnWndProc = pDefWindowProcW;
685 if (i & 2)
687 cls.lpszClassName = classA;
688 atom = RegisterClassExA(&cls);
690 else
692 cls.lpszClassName = (LPCSTR)classW;
693 atom = RegisterClassExW((WNDCLASSEXW *)&cls);
695 ok(atom != 0, "Couldn't register class, i=%d, %d\n", i, GetLastError());
697 hwnd = CreateWindowA(classA, NULL, 0, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), NULL);
698 ok(hwnd != NULL, "Couldn't create window i=%d\n", i);
700 ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
701 (void *)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), pDefWindowProcA);
702 ok(GetClassLongPtrA(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
703 (void *)GetClassLongPtrA(hwnd, GCLP_WNDPROC), pDefWindowProcA);
705 ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
706 (void *)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), pDefWindowProcW);
707 ok(GetClassLongPtrW(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
708 (void *)GetClassLongPtrW(hwnd, GCLP_WNDPROC), pDefWindowProcW);
710 DestroyWindow(hwnd);
711 UnregisterClassA((LPSTR)(DWORD_PTR)atom, GetModuleHandleA(NULL));
715 /* built-in winproc - window A/W type automatically detected */
716 ZeroMemory(&cls, sizeof(cls));
717 cls.cbSize = sizeof(cls);
718 cls.hInstance = GetModuleHandleA(NULL);
719 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
720 cls.lpszClassName = classA;
721 cls.lpfnWndProc = pDefWindowProcW;
722 atom = RegisterClassExA(&cls);
724 hwnd = CreateWindowExW(0, classW, unistring, WS_OVERLAPPEDWINDOW,
725 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleW(NULL), 0);
726 ok(IsWindowUnicode(hwnd) ||
727 broken(!IsWindowUnicode(hwnd)) /* Windows 8 and 10 */,
728 "Windows should be Unicode\n");
729 SendMessageW(hwnd, WM_GETTEXT, sizeof(buf) / sizeof(buf[0]), (LPARAM)buf);
730 if (IsWindowUnicode(hwnd))
731 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
732 else
733 ok(memcmp(buf, unistring, sizeof(unistring)) != 0, "WM_GETTEXT invalid return\n");
734 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)pDefWindowProcA);
735 ok(IsWindowUnicode(hwnd), "Windows should have remained Unicode\n");
736 if (GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA)
738 /* DefWindowProc isn't magic on wow64 */
739 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Ansi winproc is not a handle\n");
741 else
743 ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Invalid Unicode winproc\n");
744 ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Invalid Ansi winproc\n");
746 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
747 ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have switched window to ANSI\n");
749 DestroyWindow(hwnd);
750 UnregisterClassA((LPSTR)(DWORD_PTR)atom, GetModuleHandleA(NULL));
752 /* custom winproc - the same function can be used as both A and W*/
753 ZeroMemory(&cls, sizeof(cls));
754 cls.cbSize = sizeof(cls);
755 cls.hInstance = GetModuleHandleA(NULL);
756 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
757 cls.lpszClassName = classA;
758 cls.lpfnWndProc = ClassTest_WndProc2;
759 atom = RegisterClassExA(&cls);
761 hwnd = CreateWindowExW(0, classW, NULL, WS_OVERLAPPEDWINDOW,
762 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
763 ok(IsWindowUnicode(hwnd) == FALSE, "Window should be ANSI\n");
764 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
765 ok(IsWindowUnicode(hwnd), "SetWindowLongPtrW should have changed window to Unicode\n");
766 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
767 ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
769 DestroyWindow(hwnd);
770 UnregisterClassA((LPSTR)(DWORD_PTR)atom, GetModuleHandleA(NULL));
772 /* For most of the builtin controls both GetWindowLongPtrA and W returns a pointer that is executed directly
773 * by CallWindowProcA/W */
774 for (i = 0; i < NUM_NORMAL_CLASSES; i++)
776 WNDPROC procA, procW;
777 hwnd = CreateWindowExA(0, NORMAL_CLASSES[i], classA, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 680, 260,
778 NULL, NULL, NULL, 0);
779 ok(hwnd != NULL, "Couldn't create window of class %s\n", NORMAL_CLASSES[i]);
780 SetWindowTextA(hwnd, classA); /* ComboBox needs this */
781 procA = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
782 procW = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
783 ok(!IS_WNDPROC_HANDLE(procA), "procA should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procA);
784 ok(!IS_WNDPROC_HANDLE(procW), "procW should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procW);
785 CallWindowProcA(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
786 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT A/A invalid return for class %s\n", NORMAL_CLASSES[i]);
787 CallWindowProcA(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
788 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT A/W invalid return for class %s\n", NORMAL_CLASSES[i]);
789 CallWindowProcW(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
790 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT W/A invalid return for class %s\n", NORMAL_CLASSES[i]);
791 CallWindowProcW(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
792 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT W/W invalid return for class %s\n", NORMAL_CLASSES[i]);
794 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
795 ok(IS_WNDPROC_HANDLE(oldproc) == FALSE, "Class %s shouldn't return a handle\n", NORMAL_CLASSES[i]);
796 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
797 DestroyWindow(hwnd);
800 /* Edit controls are special - they return a wndproc handle when GetWindowLongPtr is called with a different A/W.
801 * On the other hand there is no W->A->W conversion so this control is treated specially. */
802 hwnd = CreateWindowW(WC_EDITW, unistring, WS_OVERLAPPEDWINDOW,
803 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
804 /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
805 ok(IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a Unicode wndproc\n");
806 ok(IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a ANSI wndproc\n");
807 /* But GetWindowLongPtr returns only a handle for the ANSI one */
808 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
809 ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return a W wndproc handle\n");
810 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
811 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
812 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
813 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
814 CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
815 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
817 SetWindowTextW(hwnd, classW);
818 CallWindowProcA((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 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc2);
822 /* SetWindowLongPtr returns a wndproc handle - like GetWindowLongPtr */
823 ok(IS_WNDPROC_HANDLE(oldproc), "Edit control should return a wndproc handle\n");
824 ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
825 SetWindowTextA(hwnd, classA); /* Windows resets the title to WideStringToMultiByte(unistring) */
826 memset(buf, 0, sizeof(buf));
827 CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
828 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
829 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
830 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
831 CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
832 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
834 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
835 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
837 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
839 DestroyWindow(hwnd);
841 hwnd = CreateWindowA(WC_EDITA, classA, WS_OVERLAPPEDWINDOW,
842 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
844 /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
845 ok(!IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)), "Edit control class should have a Unicode wndproc\n");
846 ok(!IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)), "Edit control class should have a ANSI wndproc\n");
847 /* But GetWindowLongPtr returns only a handle for the Unicode one */
848 ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return an A wndproc handle\n");
849 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
850 CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
851 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
852 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
853 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
854 CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
855 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
857 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
858 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
860 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
861 SetWindowTextW(hwnd, unistring);
862 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
863 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
864 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
865 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
866 CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
867 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
869 SetWindowTextW(hwnd, classW);
870 CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
871 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
873 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
875 DestroyWindow(hwnd);
879 static LRESULT WINAPI TestDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
881 return DefWindowProcA(hWnd, uMsg, wParam, lParam);
884 static BOOL RegisterTestDialog(HINSTANCE hInstance)
886 WNDCLASSEXA wcx;
887 ATOM atom = 0;
889 ZeroMemory(&wcx, sizeof(WNDCLASSEXA));
890 wcx.cbSize = sizeof(wcx);
891 wcx.lpfnWndProc = TestDlgProc;
892 wcx.cbClsExtra = 0;
893 wcx.cbWndExtra = DLGWINDOWEXTRA;
894 wcx.hInstance = hInstance;
895 wcx.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
896 wcx.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
897 wcx.hbrBackground = GetStockObject(WHITE_BRUSH);
898 wcx.lpszClassName = "TestDialog";
899 wcx.lpszMenuName = "TestDialog";
900 wcx.hIconSm = LoadImageA(hInstance, (LPCSTR)MAKEINTRESOURCE(5), IMAGE_ICON,
901 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
902 LR_DEFAULTCOLOR);
904 atom = RegisterClassExA(&wcx);
905 ok(atom != 0, "RegisterClassEx returned 0\n");
907 return atom;
910 /* test registering a dialog box created by using the CLASS directive in a
911 resource file, then test creating the dialog using CreateDialogParam. */
912 static void CreateDialogParamTest(HINSTANCE hInstance)
914 HWND hWndMain;
916 if (RegisterTestDialog(hInstance))
918 hWndMain = CreateDialogParamA(hInstance, "CLASS_TEST_DIALOG", NULL, 0, 0);
919 ok(hWndMain != NULL, "CreateDialogParam returned NULL\n");
920 ShowWindow(hWndMain, SW_SHOW);
921 DestroyWindow(hWndMain);
925 static const struct
927 const char name[9];
928 int value;
929 int badvalue;
930 } extra_values[] =
932 {"#32770",30,30}, /* Dialog */
933 #ifdef _WIN64
934 {"Edit",8,8},
935 #else
936 {"Edit",6,8}, /* Windows XP 64-bit returns 8 also to 32-bit applications */
937 #endif
940 static void test_extra_values(void)
942 int i;
943 for(i=0; i< sizeof(extra_values)/sizeof(extra_values[0]); i++)
945 WNDCLASSEXA wcx;
946 BOOL ret = GetClassInfoExA(NULL,extra_values[i].name,&wcx);
948 ok( ret, "GetClassInfo (0) failed for global class %s\n", extra_values[i].name);
949 if (!ret) continue;
950 ok(extra_values[i].value == wcx.cbWndExtra || broken(extra_values[i].badvalue == wcx.cbWndExtra),
951 "expected %d, got %d\n", extra_values[i].value, wcx.cbWndExtra);
955 static void test_GetClassInfo(void)
957 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
958 WNDCLASSA wc;
959 WNDCLASSEXA wcx;
960 BOOL ret;
962 SetLastError(0xdeadbeef);
963 ret = GetClassInfoA(0, "static", &wc);
964 ok(ret, "GetClassInfoA() error %d\n", GetLastError());
966 if (0) { /* crashes under XP */
967 SetLastError(0xdeadbeef);
968 ret = GetClassInfoA(0, "static", NULL);
969 ok(ret, "GetClassInfoA() error %d\n", GetLastError());
971 SetLastError(0xdeadbeef);
972 ret = GetClassInfoW(0, staticW, NULL);
973 ok(ret, "GetClassInfoW() error %d\n", GetLastError());
976 wcx.cbSize = sizeof(wcx);
977 SetLastError(0xdeadbeef);
978 ret = GetClassInfoExA(0, "static", &wcx);
979 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
981 SetLastError(0xdeadbeef);
982 ret = GetClassInfoExA(0, "static", NULL);
983 ok(!ret, "GetClassInfoExA() should fail\n");
984 ok(GetLastError() == ERROR_NOACCESS ||
985 broken(GetLastError() == 0xdeadbeef), /* win9x */
986 "expected ERROR_NOACCESS, got %d\n", GetLastError());
988 SetLastError(0xdeadbeef);
989 ret = GetClassInfoExW(0, staticW, NULL);
990 ok(!ret, "GetClassInfoExW() should fail\n");
991 ok(GetLastError() == ERROR_NOACCESS ||
992 broken(GetLastError() == 0xdeadbeef) /* NT4 */ ||
993 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
994 "expected ERROR_NOACCESS, got %d\n", GetLastError());
996 wcx.cbSize = 0;
997 wcx.lpfnWndProc = NULL;
998 SetLastError(0xdeadbeef);
999 ret = GetClassInfoExA(0, "static", &wcx);
1000 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
1001 ok(wcx.cbSize == 0, "expected 0, got %u\n", wcx.cbSize);
1002 ok(wcx.lpfnWndProc != NULL, "got null proc\n");
1004 wcx.cbSize = sizeof(wcx) - 1;
1005 wcx.lpfnWndProc = NULL;
1006 SetLastError(0xdeadbeef);
1007 ret = GetClassInfoExA(0, "static", &wcx);
1008 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
1009 ok(wcx.cbSize == sizeof(wcx) - 1, "expected sizeof(wcx)-1, got %u\n", wcx.cbSize);
1010 ok(wcx.lpfnWndProc != NULL, "got null proc\n");
1012 wcx.cbSize = sizeof(wcx) + 1;
1013 wcx.lpfnWndProc = NULL;
1014 SetLastError(0xdeadbeef);
1015 ret = GetClassInfoExA(0, "static", &wcx);
1016 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
1017 ok(wcx.cbSize == sizeof(wcx) + 1, "expected sizeof(wcx)+1, got %u\n", wcx.cbSize);
1018 ok(wcx.lpfnWndProc != NULL, "got null proc\n");
1021 static void test_icons(void)
1023 WNDCLASSEXW wcex, ret_wcex;
1024 WCHAR cls_name[] = {'I','c','o','n','T','e','s','t','C','l','a','s','s',0};
1025 HWND hwnd;
1026 HINSTANCE hinst = GetModuleHandleW(0);
1027 HICON hsmicon, hsmallnew;
1028 ICONINFO icinf;
1030 memset(&wcex, 0, sizeof wcex);
1031 wcex.cbSize = sizeof wcex;
1032 wcex.lpfnWndProc = ClassTest_WndProc;
1033 wcex.hIcon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
1034 wcex.hInstance = hinst;
1035 wcex.lpszClassName = cls_name;
1036 ok(RegisterClassExW(&wcex), "RegisterClassExW returned 0\n");
1037 hwnd = CreateWindowExW(0, cls_name, NULL, WS_OVERLAPPEDWINDOW,
1038 0, 0, 0, 0, NULL, NULL, hinst, 0);
1039 ok(hwnd != NULL, "Window was not created\n");
1041 ok(GetClassInfoExW(hinst, cls_name, &ret_wcex), "Class info was not retrieved\n");
1042 ok(wcex.hIcon == ret_wcex.hIcon, "Icons don't match\n");
1043 ok(ret_wcex.hIconSm != NULL, "hIconSm should be non-zero handle\n");
1045 hsmicon = (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM);
1046 ok(hsmicon != NULL, "GetClassLong should return non-zero handle\n");
1048 ok(SendMessageA(hwnd, WM_GETICON, ICON_BIG, 0) == 0,
1049 "WM_GETICON with ICON_BIG should not return the class icon\n");
1050 ok(SendMessageA(hwnd, WM_GETICON, ICON_SMALL, 0) == 0,
1051 "WM_GETICON with ICON_SMALL should not return the class icon\n");
1052 ok(SendMessageA(hwnd, WM_GETICON, ICON_SMALL2, 0) == 0,
1053 "WM_GETICON with ICON_SMALL2 should not return the class icon\n");
1055 hsmallnew = CopyImage(wcex.hIcon, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
1056 GetSystemMetrics(SM_CYSMICON), 0);
1057 ok(!SetClassLongPtrW(hwnd, GCLP_HICONSM, (LONG_PTR)hsmallnew),
1058 "Previous hIconSm should be zero\n");
1059 ok(hsmallnew == (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM),
1060 "Should return explicitly assigned small icon\n");
1061 ok(!GetIconInfo(hsmicon, &icinf), "Previous small icon should be destroyed\n");
1063 SetClassLongPtrW(hwnd, GCLP_HICONSM, 0);
1064 hsmicon = (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM);
1065 ok( hsmicon != NULL, "GetClassLong should return non-zero handle\n");
1067 SetClassLongPtrW(hwnd, GCLP_HICON, 0);
1068 ok(!GetClassLongPtrW(hwnd, GCLP_HICONSM), "GetClassLong should return zero handle\n");
1070 SetClassLongPtrW(hwnd, GCLP_HICON, (LONG_PTR)LoadIconW(NULL, (LPCWSTR)IDI_QUESTION));
1071 hsmicon = (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM);
1072 ok(hsmicon != NULL, "GetClassLong should return non-zero handle\n");
1073 UnregisterClassW(cls_name, hinst);
1074 ok(GetIconInfo(hsmicon, &icinf), "Icon should NOT be destroyed\n");
1076 DestroyIcon(hsmallnew);
1077 DestroyWindow(hwnd);
1080 static void create_manifest_file(const char *filename, const char *manifest)
1082 WCHAR path[MAX_PATH];
1083 HANDLE file;
1084 DWORD size;
1086 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
1087 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1088 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
1089 WriteFile(file, manifest, strlen(manifest), &size, NULL);
1090 CloseHandle(file);
1093 static HANDLE create_test_actctx(const char *file)
1095 WCHAR path[MAX_PATH];
1096 ACTCTXW actctx;
1097 HANDLE handle;
1099 MultiByteToWideChar(CP_ACP, 0, file, -1, path, MAX_PATH);
1100 memset(&actctx, 0, sizeof(ACTCTXW));
1101 actctx.cbSize = sizeof(ACTCTXW);
1102 actctx.lpSource = path;
1104 handle = CreateActCtxW(&actctx);
1105 ok(handle != INVALID_HANDLE_VALUE, "failed to create context, error %u\n", GetLastError());
1107 ok(actctx.cbSize == sizeof(actctx), "cbSize=%d\n", actctx.cbSize);
1108 ok(actctx.dwFlags == 0, "dwFlags=%d\n", actctx.dwFlags);
1109 ok(actctx.lpSource == path, "lpSource=%p\n", actctx.lpSource);
1110 ok(actctx.wProcessorArchitecture == 0, "wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
1111 ok(actctx.wLangId == 0, "wLangId=%d\n", actctx.wLangId);
1112 ok(actctx.lpAssemblyDirectory == NULL, "lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
1113 ok(actctx.lpResourceName == NULL, "lpResourceName=%p\n", actctx.lpResourceName);
1114 ok(actctx.lpApplicationName == NULL, "lpApplicationName=%p\n", actctx.lpApplicationName);
1115 ok(actctx.hModule == NULL, "hModule=%p\n", actctx.hModule);
1117 return handle;
1119 static void test_comctl32_class( const char *name )
1121 WNDCLASSA wcA;
1122 WNDCLASSW wcW;
1123 BOOL ret;
1124 HMODULE module;
1125 WCHAR nameW[20];
1126 HWND hwnd;
1128 if (name[0] == '!')
1130 char path[MAX_PATH];
1131 ULONG_PTR cookie;
1132 HANDLE context;
1134 name++;
1136 GetTempPathA(sizeof(path)/sizeof(path[0]), path);
1137 strcat(path, "comctl32_class.manifest");
1139 create_manifest_file(path, comctl32_manifest);
1140 context = create_test_actctx(path);
1141 ret = DeleteFileA(path);
1142 ok(ret, "Failed to delete manifest file, error %d.\n", GetLastError());
1144 module = GetModuleHandleA( "comctl32" );
1145 ok( !module, "comctl32 already loaded\n" );
1147 ret = ActivateActCtx(context, &cookie);
1148 ok(ret, "Failed to activate context.\n");
1150 /* Some systems load modules during context activation. In this case skip the rest of the test. */
1151 module = GetModuleHandleA( "comctl32" );
1152 ok( !module || broken(module != NULL) /* Vista/Win7 */, "comctl32 already loaded\n" );
1153 if (module)
1155 win_skip("Module loaded during context activation. Skipping tests.\n");
1156 goto skiptest;
1159 ret = GetClassInfoA( 0, name, &wcA );
1160 ok( ret || broken(!ret) /* WinXP */, "GetClassInfoA failed for %s\n", name );
1161 if (!ret)
1162 goto skiptest;
1164 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) );
1165 ret = GetClassInfoW( 0, nameW, &wcW );
1166 ok( ret, "GetClassInfoW failed for %s\n", name );
1167 module = GetModuleHandleA( "comctl32" );
1168 ok( module != 0, "comctl32 not loaded\n" );
1169 FreeLibrary( module );
1170 module = GetModuleHandleA( "comctl32" );
1171 ok( !module || broken(module != NULL) /* Vista */, "comctl32 still loaded\n" );
1172 hwnd = CreateWindowA( name, "test", WS_OVERLAPPEDWINDOW, 0, 0, 10, 10, NULL, NULL, NULL, 0 );
1173 ok( hwnd != 0, "failed to create window for %s\n", name );
1174 module = GetModuleHandleA( "comctl32" );
1175 ok( module != 0, "comctl32 not loaded\n" );
1176 DestroyWindow( hwnd );
1178 skiptest:
1179 ret = DeactivateActCtx(0, cookie);
1180 ok(ret, "Failed to deactivate context.\n");
1181 ReleaseActCtx(context);
1183 else
1185 module = GetModuleHandleA( "comctl32" );
1186 ok( !module, "comctl32 already loaded\n" );
1187 ret = GetClassInfoA( 0, name, &wcA );
1188 ok( ret || broken(!ret) /* <= winxp */, "GetClassInfoA failed for %s\n", name );
1189 if (!ret) return;
1190 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) );
1191 ret = GetClassInfoW( 0, nameW, &wcW );
1192 ok( ret, "GetClassInfoW failed for %s\n", name );
1193 module = GetModuleHandleA( "comctl32" );
1194 ok( module != 0, "comctl32 not loaded\n" );
1195 FreeLibrary( module );
1196 module = GetModuleHandleA( "comctl32" );
1197 ok( !module, "comctl32 still loaded\n" );
1198 hwnd = CreateWindowA( name, "test", WS_OVERLAPPEDWINDOW, 0, 0, 10, 10, NULL, NULL, NULL, 0 );
1199 ok( hwnd != 0, "failed to create window for %s\n", name );
1200 module = GetModuleHandleA( "comctl32" );
1201 ok( module != 0, "comctl32 not loaded\n" );
1202 DestroyWindow( hwnd );
1206 /* verify that comctl32 classes are automatically loaded by user32 */
1207 static void test_comctl32_classes(void)
1209 char path_name[MAX_PATH];
1210 PROCESS_INFORMATION info;
1211 STARTUPINFOA startup;
1212 char **argv;
1213 int i;
1215 static const char *classes[] =
1217 ANIMATE_CLASSA,
1218 WC_COMBOBOXEXA,
1219 DATETIMEPICK_CLASSA,
1220 WC_HEADERA,
1221 HOTKEY_CLASSA,
1222 WC_IPADDRESSA,
1223 WC_LISTVIEWA,
1224 MONTHCAL_CLASSA,
1225 WC_NATIVEFONTCTLA,
1226 WC_PAGESCROLLERA,
1227 PROGRESS_CLASSA,
1228 REBARCLASSNAMEA,
1229 STATUSCLASSNAMEA,
1230 "SysLink",
1231 WC_TABCONTROLA,
1232 TOOLBARCLASSNAMEA,
1233 TOOLTIPS_CLASSA,
1234 TRACKBAR_CLASSA,
1235 WC_TREEVIEWA,
1236 UPDOWN_CLASSA,
1237 "!Button",
1238 "!Edit",
1241 winetest_get_mainargs( &argv );
1242 for (i = 0; i < sizeof(classes) / sizeof(classes[0]); i++)
1244 memset( &startup, 0, sizeof(startup) );
1245 startup.cb = sizeof( startup );
1246 sprintf( path_name, "%s class %s", argv[0], classes[i] );
1247 ok( CreateProcessA( NULL, path_name, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info ),
1248 "CreateProcess failed.\n" );
1249 winetest_wait_child_process( info.hProcess );
1250 CloseHandle( info.hProcess );
1251 CloseHandle( info.hThread );
1255 static void test_IME(void)
1257 static const WCHAR ime_classW[] = {'I','M','E',0};
1259 char module_name[MAX_PATH], *ptr;
1260 MEMORY_BASIC_INFORMATION mbi;
1261 WNDCLASSW wnd_classw;
1262 WNDCLASSA wnd_class;
1263 SIZE_T size;
1264 BOOL ret;
1266 if (!GetProcAddress(GetModuleHandleA("user32.dll"), "BroadcastSystemMessageExA"))
1268 win_skip("BroadcastSystemMessageExA not available, skipping IME class test\n");
1269 return;
1272 ok(GetModuleHandleA("imm32") != 0, "imm32.dll is not loaded\n");
1274 ret = GetClassInfoA(NULL, "IME", &wnd_class);
1275 ok(ret, "GetClassInfo failed: %d\n", GetLastError());
1277 size = VirtualQuery(wnd_class.lpfnWndProc, &mbi, sizeof(mbi));
1278 ok(size == sizeof(mbi), "VirtualQuery returned %ld\n", size);
1279 if (size == sizeof(mbi)) {
1280 size = GetModuleFileNameA(mbi.AllocationBase, module_name, sizeof(module_name));
1281 ok(size, "GetModuleFileName failed\n");
1282 for (ptr = module_name+size-1; ptr > module_name; ptr--)
1283 if (*ptr == '\\' || *ptr == '/') break;
1284 if (*ptr == '\\' || *ptr=='/') ptr++;
1285 ok(!lstrcmpiA(ptr, "user32.dll") || !lstrcmpiA(ptr, "ntdll.dll"), "IME window proc implemented in %s\n", ptr);
1288 ret = GetClassInfoW(NULL, ime_classW, &wnd_classw);
1289 ok(ret, "GetClassInfo failed: %d\n", GetLastError());
1291 size = VirtualQuery(wnd_classw.lpfnWndProc, &mbi, sizeof(mbi));
1292 ok(size == sizeof(mbi), "VirtualQuery returned %ld\n", size);
1293 size = GetModuleFileNameA(mbi.AllocationBase, module_name, sizeof(module_name));
1294 ok(size, "GetModuleFileName failed\n");
1295 for (ptr = module_name+size-1; ptr > module_name; ptr--)
1296 if (*ptr == '\\' || *ptr == '/') break;
1297 if (*ptr == '\\' || *ptr=='/') ptr++;
1298 ok(!lstrcmpiA(ptr, "user32.dll") || !lstrcmpiA(ptr, "ntdll.dll"), "IME window proc implemented in %s\n", ptr);
1301 static void test_actctx_classes(void)
1303 static const char main_manifest[] =
1304 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
1305 "<assemblyIdentity version=\"4.3.2.1\" name=\"Wine.WndClass.Test\" type=\"win32\" />"
1306 "<file name=\"file.exe\">"
1307 "<windowClass>MyTestClass</windowClass>"
1308 "</file>"
1309 "</assembly>";
1310 static const char *testclass = "MyTestClass";
1311 WNDCLASSA wc;
1312 ULONG_PTR cookie;
1313 HANDLE context;
1314 BOOL ret;
1315 ATOM class;
1316 HINSTANCE hinst;
1317 char buff[64];
1318 HWND hwnd;
1319 char path[MAX_PATH];
1321 GetTempPathA(sizeof(path)/sizeof(path[0]), path);
1322 strcat(path, "actctx_classes.manifest");
1324 create_manifest_file(path, main_manifest);
1325 context = create_test_actctx(path);
1326 ret = DeleteFileA(path);
1327 ok(ret, "Failed to delete manifest file, error %d.\n", GetLastError());
1329 ret = ActivateActCtx(context, &cookie);
1330 ok(ret, "Failed to activate context.\n");
1332 memset(&wc, 0, sizeof(wc));
1333 wc.lpfnWndProc = ClassTest_WndProc;
1334 wc.hIcon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
1335 wc.lpszClassName = testclass;
1337 hinst = GetModuleHandleW(0);
1339 ret = GetClassInfoA(hinst, testclass, &wc);
1340 ok(!ret, "Expected failure.\n");
1342 class = RegisterClassA(&wc);
1343 ok(class != 0, "Failed to register class.\n");
1345 /* Class info is available by versioned and regular names. */
1346 ret = GetClassInfoA(hinst, testclass, &wc);
1347 ok(ret, "Failed to get class info.\n");
1349 hwnd = CreateWindowExA(0, testclass, "test", 0, 0, 0, 0, 0, 0, 0, hinst, 0);
1350 ok(hwnd != NULL, "Failed to create a window.\n");
1352 ret = GetClassNameA(hwnd, buff, sizeof(buff));
1353 ok(ret, "Failed to get class name.\n");
1354 ok(!strcmp(buff, testclass), "Unexpected class name.\n");
1356 ret = GetClassInfoA(hinst, "4.3.2.1!MyTestClass", &wc);
1357 ok(ret, "Failed to get class info.\n");
1359 ret = UnregisterClassA(testclass, hinst);
1360 ok(!ret, "Failed to unregister class.\n");
1362 ret = DeactivateActCtx(0, cookie);
1363 ok(ret, "Failed to deactivate context.\n");
1365 ret = GetClassInfoA(hinst, testclass, &wc);
1366 ok(!ret, "Unexpected ret val %d.\n", ret);
1368 ret = GetClassInfoA(hinst, "4.3.2.1!MyTestClass", &wc);
1369 ok(ret, "Failed to get class info.\n");
1371 ret = GetClassNameA(hwnd, buff, sizeof(buff));
1372 ok(ret, "Failed to get class name.\n");
1373 ok(!strcmp(buff, testclass), "Unexpected class name.\n");
1375 DestroyWindow(hwnd);
1377 ret = UnregisterClassA("MyTestClass", hinst);
1378 ok(!ret, "Unexpected ret value %d.\n", ret);
1380 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1381 ok(ret, "Failed to unregister class.\n");
1383 /* Register versioned class without active context. */
1384 wc.lpszClassName = "4.3.2.1!MyTestClass";
1385 class = RegisterClassA(&wc);
1386 ok(class != 0, "Failed to register class.\n");
1388 ret = ActivateActCtx(context, &cookie);
1389 ok(ret, "Failed to activate context.\n");
1391 wc.lpszClassName = "MyTestClass";
1392 class = RegisterClassA(&wc);
1393 ok(class == 0, "Expected failure.\n");
1395 ret = DeactivateActCtx(0, cookie);
1396 ok(ret, "Failed to deactivate context.\n");
1398 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1399 ok(ret, "Failed to unregister class.\n");
1401 /* Only versioned name is registered. */
1402 ret = ActivateActCtx(context, &cookie);
1403 ok(ret, "Failed to activate context.\n");
1405 wc.lpszClassName = "MyTestClass";
1406 class = RegisterClassA(&wc);
1407 ok(class != 0, "Failed to register class\n");
1409 ret = DeactivateActCtx(0, cookie);
1410 ok(ret, "Failed to deactivate context.\n");
1412 ret = GetClassInfoA(hinst, "MyTestClass", &wc);
1413 ok(!ret, "Expected failure.\n");
1415 ret = GetClassInfoA(hinst, "4.3.2.1!MyTestClass", &wc);
1416 ok(ret, "Failed to get class info.\n");
1418 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1419 ok(ret, "Failed to unregister class.\n");
1421 /* Register regular name first, it's not considered when versioned name is registered. */
1422 wc.lpszClassName = "MyTestClass";
1423 class = RegisterClassA(&wc);
1424 ok(class != 0, "Failed to register class.\n");
1426 ret = ActivateActCtx(context, &cookie);
1427 ok(ret, "Failed to activate context.\n");
1429 wc.lpszClassName = "MyTestClass";
1430 class = RegisterClassA(&wc);
1431 ok(class != 0, "Failed to register class.\n");
1433 ret = DeactivateActCtx(0, cookie);
1434 ok(ret, "Failed to deactivate context.\n");
1436 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1437 ok(ret, "Failed to unregister class.\n");
1439 ret = UnregisterClassA("MyTestClass", hinst);
1440 ok(ret, "Failed to unregister class.\n");
1442 ReleaseActCtx(context);
1445 START_TEST(class)
1447 char **argv;
1448 HANDLE hInstance = GetModuleHandleA( NULL );
1449 int argc = winetest_get_mainargs( &argv );
1451 if (argc >= 3)
1453 test_comctl32_class( argv[2] );
1454 return;
1457 test_IME();
1458 test_GetClassInfo();
1459 test_extra_values();
1461 if (!GetModuleHandleW(0))
1463 trace("Class test is incompatible with Win9x implementation, skipping\n");
1464 return;
1467 ClassTest(hInstance,FALSE);
1468 ClassTest(hInstance,TRUE);
1469 CreateDialogParamTest(hInstance);
1470 test_styles();
1471 test_builtinproc();
1472 test_icons();
1473 test_comctl32_classes();
1474 test_actctx_classes();
1476 /* this test unregisters the Button class so it should be executed at the end */
1477 test_instances();