ntoskrnl.exe: Implement ExAcquireFastMutex and ExReleaseFastMutex.
[wine.git] / dlls / user32 / tests / class.c
blob2702fa00b93e03ea4cb29c8c68f8a88e9968a2dd
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(GetClipboardFormatNameW(classatom, str, ARRAY_SIZE(str)) != 0, "atom not found\n");
120 ok(!RegisterClassW (&cls),
121 "RegisterClass of the same class should fail for the second time\n");
123 /* Setup windows */
124 hTestWnd = CreateWindowW (className, winName,
125 WS_OVERLAPPEDWINDOW + WS_HSCROLL + WS_VSCROLL,
126 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 0,
127 0, hInstance, 0);
129 ok(hTestWnd!=0, "Failed to create window\n");
131 /* test initial values of valid classwords */
132 for(i=0; i<NUMCLASSWORDS; i++)
134 SetLastError(0);
135 ok(!GetClassLongW(hTestWnd,i*sizeof (DWORD)),
136 "GetClassLongW initial value nonzero!\n");
137 ok(!GetLastError(),
138 "GetClassLongW failed!\n");
141 if (0)
144 * GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD))
145 * does not fail on Win 98, though MSDN says it should
147 SetLastError(0);
148 GetClassLongW(hTestWnd, NUMCLASSWORDS*sizeof(DWORD));
149 ok(GetLastError(),
150 "GetClassLongW() with invalid offset did not fail\n");
153 /* set values of valid class words */
154 for(i=0; i<NUMCLASSWORDS; i++)
156 SetLastError(0);
157 ok(!SetClassLongW(hTestWnd,i*sizeof(DWORD),i+1),
158 "GetClassLongW(%d) initial value nonzero!\n",i);
159 ok(!GetLastError(),
160 "SetClassLongW(%d) failed!\n",i);
163 /* test values of valid classwords that we set */
164 for(i=0; i<NUMCLASSWORDS; i++)
166 SetLastError(0);
167 ok( (i+1) == GetClassLongW(hTestWnd,i*sizeof (DWORD)),
168 "GetClassLongW value doesn't match what was set!\n");
169 ok(!GetLastError(),
170 "GetClassLongW failed!\n");
173 /* check GetClassName */
174 i = GetClassNameW(hTestWnd, str, ARRAY_SIZE(str));
175 ok(i == lstrlenW(className),
176 "GetClassName returned incorrect length\n");
177 ok(!lstrcmpW(className,str),
178 "GetClassName returned incorrect name for this window's class\n");
180 /* check GetClassInfo with our hInstance */
181 if((test_atom = GetClassInfoW(hInstance, str, &wc)))
183 ok(test_atom == classatom,
184 "class atom did not match\n");
185 ok(wc.cbClsExtra == cls.cbClsExtra,
186 "cbClsExtra did not match\n");
187 ok(wc.cbWndExtra == cls.cbWndExtra,
188 "cbWndExtra did not match\n");
189 ok(wc.hbrBackground == cls.hbrBackground,
190 "hbrBackground did not match\n");
191 ok(wc.hCursor== cls.hCursor,
192 "hCursor did not match\n");
193 ok(wc.hInstance== cls.hInstance,
194 "hInstance did not match\n");
196 else
197 ok(FALSE,"GetClassInfo (hinstance) failed!\n");
199 /* check GetClassInfo with zero hInstance */
200 if(global)
202 if((test_atom = GetClassInfoW(0, str, &wc)))
204 ok(test_atom == classatom,
205 "class atom did not match %x != %x\n", test_atom, classatom);
206 ok(wc.cbClsExtra == cls.cbClsExtra,
207 "cbClsExtra did not match %x!=%x\n",wc.cbClsExtra,cls.cbClsExtra);
208 ok(wc.cbWndExtra == cls.cbWndExtra,
209 "cbWndExtra did not match %x!=%x\n",wc.cbWndExtra,cls.cbWndExtra);
210 ok(wc.hbrBackground == cls.hbrBackground,
211 "hbrBackground did not match %p!=%p\n",wc.hbrBackground,cls.hbrBackground);
212 ok(wc.hCursor== cls.hCursor,
213 "hCursor did not match %p!=%p\n",wc.hCursor,cls.hCursor);
214 ok(!wc.hInstance,
215 "hInstance not zero for global class %p\n",wc.hInstance);
217 else
218 ok(FALSE,"GetClassInfo (0) failed for global class!\n");
220 else
222 ok(!GetClassInfoW(0, str, &wc),
223 "GetClassInfo (0) succeeded for local class!\n");
226 ok(!UnregisterClassW(className, hInstance),
227 "Unregister class succeeded with window existing\n");
229 ok(DestroyWindow(hTestWnd),
230 "DestroyWindow() failed!\n");
232 ok(UnregisterClassW(className, hInstance),
233 "UnregisterClass() failed\n");
235 ok(GetClipboardFormatNameW(classatom, str, ARRAY_SIZE(str)) == 0,
236 "atom still found\n");
237 return;
240 static void check_style( const char *name, int must_exist, UINT style, UINT ignore )
242 WNDCLASSA wc;
244 if (GetClassInfoA( 0, name, &wc ))
246 ok( !(~wc.style & style & ~ignore), "System class %s is missing bits %x (%08x/%08x)\n",
247 name, ~wc.style & style, wc.style, style );
248 ok( !(wc.style & ~style), "System class %s has extra bits %x (%08x/%08x)\n",
249 name, wc.style & ~style, wc.style, style );
251 else
252 ok( !must_exist, "System class %s does not exist\n", name );
255 /* test styles of system classes */
256 static void test_styles(void)
258 /* check style bits */
259 check_style( "Button", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
260 check_style( "ComboBox", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
261 check_style( "Edit", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
262 check_style( "ListBox", 1, CS_PARENTDC | CS_DBLCLKS, CS_PARENTDC /*FIXME*/ );
263 check_style( "MDIClient", 1, 0, 0 );
264 check_style( "ScrollBar", 1, CS_PARENTDC | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW, 0 );
265 check_style( "Static", 1, CS_PARENTDC | CS_DBLCLKS, 0 );
266 check_style( "ComboLBox", 1, CS_SAVEBITS | CS_DBLCLKS, 0 );
267 check_style( "DDEMLEvent", 0, 0, 0 );
268 check_style( "Message", 0, 0, 0 );
269 check_style( "#32768", 1, CS_DROPSHADOW | CS_SAVEBITS | CS_DBLCLKS, CS_DROPSHADOW ); /* menu */
270 check_style( "#32769", 1, CS_DBLCLKS, 0 ); /* desktop */
271 check_style( "#32770", 1, CS_SAVEBITS | CS_DBLCLKS, 0 ); /* dialog */
272 todo_wine { check_style( "#32771", 1, CS_SAVEBITS | CS_HREDRAW | CS_VREDRAW, 0 ); } /* task switch */
273 check_style( "#32772", 1, 0, 0 ); /* icon title */
276 static void check_class_(int line, HINSTANCE inst, const char *name, const char *menu_name)
278 WNDCLASSA wc;
279 UINT atom = GetClassInfoA(inst,name,&wc);
280 ok_(__FILE__,line)( atom, "Class %s %p not found\n", name, inst );
281 if (atom)
283 if (wc.lpszMenuName && menu_name)
284 ok_(__FILE__,line)( !strcmp( menu_name, wc.lpszMenuName ),
285 "Wrong name %s/%s for class %s %p\n",
286 wc.lpszMenuName, menu_name, name, inst );
287 else
288 ok_(__FILE__,line)( !menu_name == !wc.lpszMenuName, "Wrong name %p/%p for class %s %p\n",
289 wc.lpszMenuName, menu_name, name, inst );
292 #define check_class(inst,name,menu) check_class_(__LINE__,inst,name,menu)
294 static void check_instance_( int line, const char *name, HINSTANCE inst,
295 HINSTANCE info_inst, HINSTANCE gcl_inst )
297 WNDCLASSA wc;
298 HWND hwnd;
300 ok_(__FILE__,line)( GetClassInfoA( inst, name, &wc ), "Couldn't find class %s inst %p\n", name, inst );
301 ok_(__FILE__,line)( wc.hInstance == info_inst, "Wrong info instance %p/%p for class %s\n",
302 wc.hInstance, info_inst, name );
303 hwnd = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, inst, 0 );
304 ok_(__FILE__,line)( hwnd != NULL, "Couldn't create window for class %s inst %p\n", name, inst );
305 ok_(__FILE__,line)( (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ) == gcl_inst,
306 "Wrong GCL instance %p/%p for class %s\n",
307 (HINSTANCE)GetClassLongPtrA( hwnd, GCLP_HMODULE ), gcl_inst, name );
308 ok_(__FILE__,line)( (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ) == inst,
309 "Wrong GWL instance %p/%p for window %s\n",
310 (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE ), inst, name );
311 ok_(__FILE__,line)(!UnregisterClassA(name, inst),
312 "UnregisterClassA should fail while exists a class window\n");
313 ok_(__FILE__,line)(GetLastError() == ERROR_CLASS_HAS_WINDOWS,
314 "GetLastError() should be set to ERROR_CLASS_HAS_WINDOWS not %d\n", GetLastError());
315 DestroyWindow(hwnd);
317 #define check_instance(name,inst,info_inst,gcl_inst) check_instance_(__LINE__,name,inst,info_inst,gcl_inst)
319 struct class_info
321 const char *name;
322 HINSTANCE inst, info_inst, gcl_inst;
325 static DWORD WINAPI thread_proc(void *param)
327 struct class_info *class_info = param;
329 check_instance(class_info->name, class_info->inst, class_info->info_inst, class_info->gcl_inst);
331 return 0;
334 static void check_thread_instance( const char *name, HINSTANCE inst, HINSTANCE info_inst, HINSTANCE gcl_inst )
336 HANDLE hThread;
337 DWORD tid;
338 struct class_info class_info;
340 class_info.name = name;
341 class_info.inst = inst;
342 class_info.info_inst = info_inst;
343 class_info.gcl_inst = gcl_inst;
345 hThread = CreateThread(NULL, 0, thread_proc, &class_info, 0, &tid);
346 ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
347 ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
348 CloseHandle(hThread);
351 /* test various instance parameters */
352 static void test_instances(void)
354 WNDCLASSA cls, wc;
355 WNDCLASSEXA wcexA;
356 HWND hwnd, hwnd2;
357 const char *name = "__test__";
358 HINSTANCE kernel32 = GetModuleHandleA("kernel32");
359 HINSTANCE user32 = GetModuleHandleA("user32");
360 HINSTANCE main_module = GetModuleHandleA(NULL);
361 HINSTANCE zero_instance = 0;
362 DWORD r;
363 char buffer[0x10];
365 memset( &cls, 0, sizeof(cls) );
366 cls.style = CS_HREDRAW | CS_VREDRAW;
367 cls.lpfnWndProc = ClassTest_WndProc;
368 cls.cbClsExtra = 0;
369 cls.cbWndExtra = 0;
370 cls.lpszClassName = name;
372 cls.lpszMenuName = "main_module";
373 cls.hInstance = main_module;
375 ok( RegisterClassA( &cls ), "Failed to register local class for main module\n" );
376 check_class( main_module, name, "main_module" );
377 check_instance( name, main_module, main_module, main_module );
378 check_thread_instance( name, main_module, main_module, main_module );
380 cls.lpszMenuName = "kernel32";
381 cls.hInstance = kernel32;
382 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
383 check_class( kernel32, name, "kernel32" );
384 check_class( main_module, name, "main_module" );
385 check_instance( name, kernel32, kernel32, kernel32 );
386 check_thread_instance( name, kernel32, kernel32, kernel32 );
387 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
389 ZeroMemory(&wcexA, sizeof(wcexA));
390 wcexA.lpfnWndProc = DefWindowProcA;
391 wcexA.lpszClassName = "__classex_test__";
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) + 1;
398 ok( ((RegisterClassExA( &wcexA ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
399 "Succeeded with invalid number of cbSize bytes\n");
400 SetLastError(0xdeadbeef);
401 wcexA.cbSize = sizeof(wcexA);
402 ok( RegisterClassExA( &wcexA ), "Failed with valid number of cbSize bytes\n");
403 wcexA.cbSize = 0xdeadbeef;
404 ok( GetClassInfoExA(main_module, wcexA.lpszClassName, &wcexA), "GetClassInfoEx failed\n");
405 ok( wcexA.cbSize == 0xdeadbeef, "GetClassInfoEx returned wrong cbSize value %d\n", wcexA.cbSize);
406 UnregisterClassA(wcexA.lpszClassName, main_module);
408 /* Bug 2631 - Supplying an invalid number of bytes fails */
409 cls.cbClsExtra = 0;
410 cls.cbWndExtra = -1;
411 SetLastError(0xdeadbeef);
412 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
413 "Failed with invalid number of WndExtra bytes\n");
415 cls.cbClsExtra = -1;
416 cls.cbWndExtra = 0;
417 SetLastError(0xdeadbeef);
418 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
419 "Failed with invalid number of ClsExtra bytes\n");
421 cls.cbClsExtra = -1;
422 cls.cbWndExtra = -1;
423 SetLastError(0xdeadbeef);
424 ok( ((RegisterClassA( &cls ) == 0) && (GetLastError() == ERROR_INVALID_PARAMETER)),
425 "Failed with invalid number of ClsExtra and cbWndExtra bytes\n");
427 cls.cbClsExtra = 0;
428 cls.cbWndExtra = 0;
429 SetLastError(0xdeadbeef);
431 /* setting global flag doesn't change status of class */
432 hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
433 ok( hwnd != 0, "CreateWindow failed error %u\n", GetLastError());
434 SetClassLongA( hwnd, GCL_STYLE, CS_GLOBALCLASS );
435 cls.lpszMenuName = "kernel32";
436 cls.hInstance = kernel32;
437 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
438 check_class( kernel32, name, "kernel32" );
439 check_class( main_module, name, "main_module" );
440 check_instance( name, kernel32, kernel32, kernel32 );
441 check_instance( name, main_module, main_module, main_module );
442 check_thread_instance( name, kernel32, kernel32, kernel32 );
443 check_thread_instance( name, main_module, main_module, main_module );
444 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
446 /* changing the instance doesn't make it global */
447 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0 );
448 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
449 check_class( kernel32, name, "kernel32" );
450 check_instance( name, kernel32, kernel32, kernel32 );
451 check_thread_instance( name, kernel32, kernel32, kernel32 );
452 ok( !GetClassInfoA( 0, name, &wc ), "Class found with null instance\n" );
453 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
455 /* GetClassInfo with instance 0 finds user32 instance */
456 SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)user32 );
457 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
458 if (!GetClassInfoA( 0, name, &wc )) zero_instance = user32; /* instance 0 not supported on wow64 */
459 else
461 check_instance( name, 0, 0, kernel32 );
462 check_thread_instance( name, 0, 0, kernel32 );
464 check_class( kernel32, name, "kernel32" );
465 check_class( user32, name, "main_module" );
466 check_class( zero_instance, name, "main_module" );
467 check_instance( name, kernel32, kernel32, kernel32 );
468 check_instance( name, user32, zero_instance, user32 );
469 check_thread_instance( name, kernel32, kernel32, kernel32 );
470 check_thread_instance( name, user32, zero_instance, user32 );
471 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
473 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0x12345678 );
474 ok( RegisterClassA( &cls ), "Failed to register local class for kernel32\n" );
475 check_class( kernel32, name, "kernel32" );
476 check_class( (HINSTANCE)0x12345678, name, "main_module" );
477 check_instance( name, kernel32, kernel32, kernel32 );
478 check_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
479 check_thread_instance( name, kernel32, kernel32, kernel32 );
480 check_thread_instance( name, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0x12345678 );
481 ok( !GetClassInfoA( 0, name, &wc ), "Class found with null instance\n" );
483 /* creating a window with instance 0 uses the first class found */
484 cls.hInstance = (HINSTANCE)0xdeadbeef;
485 cls.lpszMenuName = "deadbeef";
486 cls.style = 3;
487 ok( RegisterClassA( &cls ), "Failed to register local class for deadbeef\n" );
488 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
489 ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0xdeadbeef,
490 "Didn't get deadbeef class for null instance\n" );
491 DestroyWindow( hwnd2 );
492 ok( UnregisterClassA( name, (HINSTANCE)0xdeadbeef ), "Unregister failed for deadbeef\n" );
494 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
495 ok( (HINSTANCE)GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == kernel32,
496 "Didn't get kernel32 class for null instance\n" );
497 DestroyWindow( hwnd2 );
499 r = GetClassNameA( hwnd, buffer, 4 );
500 ok( r == 3, "expected 3, got %d\n", r );
501 ok( !strcmp( buffer, "__t"), "name wrong: %s\n", buffer );
503 ok( UnregisterClassA( name, kernel32 ), "Unregister failed for kernel32\n" );
505 hwnd2 = CreateWindowExA( 0, name, "test_window", 0, 0, 0, 0, 0, 0, 0, NULL, 0 );
506 ok( GetClassLongPtrA( hwnd2, GCLP_HMODULE ) == 0x12345678,
507 "Didn't get 12345678 class for null instance\n" );
508 DestroyWindow( hwnd2 );
510 SetClassLongPtrA( hwnd, GCLP_HMODULE, (LONG_PTR)main_module );
511 DestroyWindow( hwnd );
513 /* null handle means the same thing as main module */
514 cls.lpszMenuName = "null";
515 cls.hInstance = 0;
516 ok( !RegisterClassA( &cls ), "Succeeded registering local class for null instance\n" );
517 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
518 ok( UnregisterClassA( name, main_module ), "Unregister failed for main module\n" );
520 ok( RegisterClassA( &cls ), "Failed to register local class for null instance\n" );
521 /* must be found with main module handle */
522 check_class( main_module, name, "null" );
523 check_instance( name, main_module, main_module, main_module );
524 check_thread_instance( name, main_module, main_module, main_module );
525 ok( !GetClassInfoA( 0, name, &wc ), "Class found with null instance\n" );
526 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
527 ok( UnregisterClassA( name, 0 ), "Unregister failed for null instance\n" );
529 /* registering for user32 always fails */
530 cls.lpszMenuName = "user32";
531 cls.hInstance = user32;
532 ok( !RegisterClassA( &cls ), "Succeeded registering local class for user32\n" );
533 ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
534 cls.style |= CS_GLOBALCLASS;
535 ok( !RegisterClassA( &cls ), "Succeeded registering global class for user32\n" );
536 ok( GetLastError() == ERROR_INVALID_PARAMETER, "Wrong error code %d\n", GetLastError() );
538 /* unregister is OK though */
539 cls.hInstance = main_module;
540 ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
541 ok( UnregisterClassA( name, user32 ), "Unregister failed for user32\n" );
543 /* instance doesn't matter for global class */
544 cls.style |= CS_GLOBALCLASS;
545 cls.lpszMenuName = "main_module";
546 cls.hInstance = main_module;
547 ok( RegisterClassA( &cls ), "Failed to register global class for main module\n" );
548 cls.lpszMenuName = "kernel32";
549 cls.hInstance = kernel32;
550 ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
551 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
552 /* even if global flag is cleared */
553 hwnd = CreateWindowExA( 0, name, "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
554 SetClassLongA( hwnd, GCL_STYLE, 0 );
555 ok( !RegisterClassA( &cls ), "Succeeded registering local class for kernel32\n" );
556 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
558 check_class( main_module, name, "main_module" );
559 check_class( kernel32, name, "main_module" );
560 check_class( 0, name, "main_module" );
561 check_class( (HINSTANCE)0x12345678, name, "main_module" );
562 check_instance( name, main_module, main_module, main_module );
563 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
564 check_thread_instance( name, main_module, main_module, main_module );
565 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, main_module );
567 /* changing the instance for global class doesn't make much difference */
568 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
569 check_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
570 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
571 check_thread_instance( name, main_module, main_module, (HINSTANCE)0xdeadbeef );
572 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef );
574 DestroyWindow( hwnd );
575 ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
576 ok( !UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister succeeded the second time\n" );
577 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
579 cls.hInstance = (HINSTANCE)0x12345678;
580 ok( RegisterClassA( &cls ), "Failed to register global class for dummy instance\n" );
581 check_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
582 check_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
583 check_thread_instance( name, main_module, main_module, (HINSTANCE)0x12345678 );
584 check_thread_instance( name, (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, (HINSTANCE)0x12345678 );
585 ok( UnregisterClassA( name, (HINSTANCE)0x87654321 ), "Unregister failed for main module global\n" );
587 /* check system classes */
589 /* we cannot register a global class with the name of a system class */
590 cls.style |= CS_GLOBALCLASS;
591 cls.lpszMenuName = "button_main_module";
592 cls.lpszClassName = "BUTTON";
593 cls.hInstance = main_module;
594 ok( !RegisterClassA( &cls ), "Succeeded registering global button class for main module\n" );
595 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
596 cls.hInstance = kernel32;
597 ok( !RegisterClassA( &cls ), "Succeeded registering global button class for kernel32\n" );
598 ok( GetLastError() == ERROR_CLASS_ALREADY_EXISTS, "Wrong error code %d\n", GetLastError() );
600 /* local class is OK however */
601 cls.style &= ~CS_GLOBALCLASS;
602 cls.lpszMenuName = "button_main_module";
603 cls.hInstance = main_module;
604 ok( RegisterClassA( &cls ), "Failed to register local button class for main module\n" );
605 check_class( main_module, "BUTTON", "button_main_module" );
606 cls.lpszMenuName = "button_kernel32";
607 cls.hInstance = kernel32;
608 ok( RegisterClassA( &cls ), "Failed to register local button class for kernel32\n" );
609 check_class( kernel32, "BUTTON", "button_kernel32" );
610 check_class( main_module, "BUTTON", "button_main_module" );
611 ok( UnregisterClassA( "BUTTON", kernel32 ), "Unregister failed for kernel32 button\n" );
612 ok( UnregisterClassA( "BUTTON", main_module ), "Unregister failed for main module button\n" );
613 /* GetClassInfo sets instance to passed value for global classes */
614 check_instance( "BUTTON", 0, 0, user32 );
615 check_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
616 check_instance( "BUTTON", user32, zero_instance, user32 );
617 check_thread_instance( "BUTTON", 0, 0, user32 );
618 check_thread_instance( "BUTTON", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
619 check_thread_instance( "BUTTON", user32, zero_instance, user32 );
621 /* we can unregister system classes */
622 ok( GetClassInfoA( 0, "BUTTON", &wc ), "Button class not found with null instance\n" );
623 ok( GetClassInfoA( kernel32, "BUTTON", &wc ), "Button class not found with kernel32\n" );
624 ok( UnregisterClassA( "BUTTON", (HINSTANCE)0x12345678 ), "Failed to unregister button\n" );
625 ok( !UnregisterClassA( "BUTTON", (HINSTANCE)0x87654321 ), "Unregistered button a second time\n" );
626 ok( GetLastError() == ERROR_CLASS_DOES_NOT_EXIST, "Wrong error code %d\n", GetLastError() );
627 ok( !GetClassInfoA( 0, "BUTTON", &wc ), "Button still exists\n" );
628 /* last error not set reliably */
630 /* we can change the instance of a system class */
631 check_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
632 check_thread_instance( "EDIT", (HINSTANCE)0xdeadbeef, (HINSTANCE)0xdeadbeef, user32 );
633 hwnd = CreateWindowExA( 0, "EDIT", "test", 0, 0, 0, 0, 0, 0, 0, main_module, 0 );
634 SetClassLongPtrA( hwnd, GCLP_HMODULE, 0xdeadbeef );
635 check_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
636 check_thread_instance( "EDIT", (HINSTANCE)0x12345678, (HINSTANCE)0x12345678, (HINSTANCE)0xdeadbeef );
637 DestroyWindow(hwnd);
640 static void test_builtinproc(void)
642 /* Edit behaves differently */
643 static const CHAR NORMAL_CLASSES[][10] = {
644 "Button",
645 "Static",
646 "ComboBox",
647 "ComboLBox",
648 "ListBox",
649 "ScrollBar",
650 "#32770", /* dialog */
652 static const char classA[] = "deftest";
653 static const WCHAR classW[] = {'d','e','f','t','e','s','t',0};
654 WCHAR unistring[] = {0x142, 0x40e, 0x3b4, 0}; /* a string that would be destroyed by a W->A->W conversion */
655 WNDPROC pDefWindowProcA, pDefWindowProcW;
656 WNDPROC pNtdllDefWindowProcA, pNtdllDefWindowProcW;
657 WNDPROC oldproc;
658 WNDCLASSEXA cls; /* the memory layout of WNDCLASSEXA and WNDCLASSEXW is the same */
659 WCHAR buf[128];
660 ATOM atom;
661 HWND hwnd;
662 unsigned int i;
664 pDefWindowProcA = (void *)GetProcAddress(GetModuleHandleA("user32.dll"), "DefWindowProcA");
665 pDefWindowProcW = (void *)GetProcAddress(GetModuleHandleA("user32.dll"), "DefWindowProcW");
666 pNtdllDefWindowProcA = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtdllDefWindowProc_A");
667 pNtdllDefWindowProcW = (void *)GetProcAddress(GetModuleHandleA("ntdll.dll"), "NtdllDefWindowProc_W");
669 /* On Vista+, the user32.dll export DefWindowProcA/W is forwarded to */
670 /* ntdll.NtdllDefWindowProc_A/W. However, the wndproc returned by */
671 /* GetClassLong/GetWindowLong points to an unexported user32 function */
672 if (pDefWindowProcA == pNtdllDefWindowProcA &&
673 pDefWindowProcW == pNtdllDefWindowProcW)
674 skip("user32.DefWindowProcX forwarded to ntdll.NtdllDefWindowProc_X\n");
675 else
677 for (i = 0; i < 4; i++)
679 ZeroMemory(&cls, sizeof(cls));
680 cls.cbSize = sizeof(cls);
681 cls.hInstance = GetModuleHandleA(NULL);
682 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
683 if (i & 1)
684 cls.lpfnWndProc = pDefWindowProcA;
685 else
686 cls.lpfnWndProc = pDefWindowProcW;
688 if (i & 2)
690 cls.lpszClassName = classA;
691 atom = RegisterClassExA(&cls);
693 else
695 cls.lpszClassName = (LPCSTR)classW;
696 atom = RegisterClassExW((WNDCLASSEXW *)&cls);
698 ok(atom != 0, "Couldn't register class, i=%d, %d\n", i, GetLastError());
700 hwnd = CreateWindowA(classA, NULL, 0, 0, 0, 100, 100, NULL, NULL, GetModuleHandleA(NULL), NULL);
701 ok(hwnd != NULL, "Couldn't create window i=%d\n", i);
703 ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
704 (void *)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), pDefWindowProcA);
705 ok(GetClassLongPtrA(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcA, "Wrong ANSI wndproc: %p vs %p\n",
706 (void *)GetClassLongPtrA(hwnd, GCLP_WNDPROC), pDefWindowProcA);
708 ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
709 (void *)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), pDefWindowProcW);
710 ok(GetClassLongPtrW(hwnd, GCLP_WNDPROC) == (ULONG_PTR)pDefWindowProcW, "Wrong Unicode wndproc: %p vs %p\n",
711 (void *)GetClassLongPtrW(hwnd, GCLP_WNDPROC), pDefWindowProcW);
713 DestroyWindow(hwnd);
714 UnregisterClassA((LPSTR)(DWORD_PTR)atom, GetModuleHandleA(NULL));
718 /* built-in winproc - window A/W type automatically detected */
719 ZeroMemory(&cls, sizeof(cls));
720 cls.cbSize = sizeof(cls);
721 cls.hInstance = GetModuleHandleA(NULL);
722 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
723 cls.lpszClassName = classA;
724 cls.lpfnWndProc = pDefWindowProcW;
725 atom = RegisterClassExA(&cls);
727 hwnd = CreateWindowExW(0, classW, unistring, WS_OVERLAPPEDWINDOW,
728 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleW(NULL), 0);
729 ok(IsWindowUnicode(hwnd) ||
730 broken(!IsWindowUnicode(hwnd)) /* Windows 8 and 10 */,
731 "Windows should be Unicode\n");
732 SendMessageW(hwnd, WM_GETTEXT, ARRAY_SIZE(buf), (LPARAM)buf);
733 if (IsWindowUnicode(hwnd))
734 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
735 else
736 ok(memcmp(buf, unistring, sizeof(unistring)) != 0, "WM_GETTEXT invalid return\n");
737 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)pDefWindowProcA);
738 ok(IsWindowUnicode(hwnd), "Windows should have remained Unicode\n");
739 if (GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA)
741 /* DefWindowProc isn't magic on wow64 */
742 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Ansi winproc is not a handle\n");
744 else
746 ok(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcW, "Invalid Unicode winproc\n");
747 ok(GetWindowLongPtrA(hwnd, GWLP_WNDPROC) == (LONG_PTR)pDefWindowProcA, "Invalid Ansi winproc\n");
749 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
750 ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have switched window to ANSI\n");
752 DestroyWindow(hwnd);
753 UnregisterClassA((LPSTR)(DWORD_PTR)atom, GetModuleHandleA(NULL));
755 /* custom winproc - the same function can be used as both A and W*/
756 ZeroMemory(&cls, sizeof(cls));
757 cls.cbSize = sizeof(cls);
758 cls.hInstance = GetModuleHandleA(NULL);
759 cls.hbrBackground = GetStockObject (WHITE_BRUSH);
760 cls.lpszClassName = classA;
761 cls.lpfnWndProc = ClassTest_WndProc2;
762 atom = RegisterClassExA(&cls);
764 hwnd = CreateWindowExW(0, classW, NULL, WS_OVERLAPPEDWINDOW,
765 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, GetModuleHandleA(NULL), 0);
766 ok(IsWindowUnicode(hwnd) == FALSE, "Window should be ANSI\n");
767 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
768 ok(IsWindowUnicode(hwnd), "SetWindowLongPtrW should have changed window to Unicode\n");
769 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
770 ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
772 DestroyWindow(hwnd);
773 UnregisterClassA((LPSTR)(DWORD_PTR)atom, GetModuleHandleA(NULL));
775 /* For most of the builtin controls both GetWindowLongPtrA and W returns a pointer that is executed directly
776 * by CallWindowProcA/W */
777 for (i = 0; i < ARRAY_SIZE(NORMAL_CLASSES); i++)
779 WNDPROC procA, procW;
780 hwnd = CreateWindowExA(0, NORMAL_CLASSES[i], classA, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 680, 260,
781 NULL, NULL, NULL, 0);
782 ok(hwnd != NULL, "Couldn't create window of class %s\n", NORMAL_CLASSES[i]);
783 SetWindowTextA(hwnd, classA); /* ComboBox needs this */
784 procA = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC);
785 procW = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
786 ok(!IS_WNDPROC_HANDLE(procA), "procA should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procA);
787 ok(!IS_WNDPROC_HANDLE(procW), "procW should not be a handle for %s (%p)\n", NORMAL_CLASSES[i], procW);
788 CallWindowProcA(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
789 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT A/A invalid return for class %s\n", NORMAL_CLASSES[i]);
790 CallWindowProcA(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
791 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT A/W invalid return for class %s\n", NORMAL_CLASSES[i]);
792 CallWindowProcW(procA, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
793 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT W/A invalid return for class %s\n", NORMAL_CLASSES[i]);
794 CallWindowProcW(procW, hwnd, WM_GETTEXT, 120, (LPARAM)buf);
795 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT W/W invalid return for class %s\n", NORMAL_CLASSES[i]);
797 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
798 ok(IS_WNDPROC_HANDLE(oldproc) == FALSE, "Class %s shouldn't return a handle\n", NORMAL_CLASSES[i]);
799 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
800 DestroyWindow(hwnd);
803 /* Edit controls are special - they return a wndproc handle when GetWindowLongPtr is called with a different A/W.
804 * On the other hand there is no W->A->W conversion so this control is treated specially. */
805 hwnd = CreateWindowW(WC_EDITW, unistring, WS_OVERLAPPEDWINDOW,
806 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
807 /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
808 ok(IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a Unicode wndproc\n");
809 ok(IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)) == FALSE, "Edit control class should have a ANSI wndproc\n");
810 /* But GetWindowLongPtr returns only a handle for the ANSI one */
811 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
812 ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return a W wndproc handle\n");
813 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
814 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
815 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
816 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
817 CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
818 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
820 SetWindowTextW(hwnd, classW);
821 CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
822 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
824 oldproc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc2);
825 /* SetWindowLongPtr returns a wndproc handle - like GetWindowLongPtr */
826 ok(IS_WNDPROC_HANDLE(oldproc), "Edit control should return a wndproc handle\n");
827 ok(IsWindowUnicode(hwnd) == FALSE, "SetWindowLongPtrA should have changed window to ANSI\n");
828 SetWindowTextA(hwnd, classA); /* Windows resets the title to WideStringToMultiByte(unistring) */
829 memset(buf, 0, sizeof(buf));
830 CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
831 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
832 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
833 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
834 CallWindowProcW((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 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
838 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
840 SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
842 DestroyWindow(hwnd);
844 hwnd = CreateWindowA(WC_EDITA, classA, WS_OVERLAPPEDWINDOW,
845 CW_USEDEFAULT, CW_USEDEFAULT, 680, 260, NULL, NULL, NULL, 0);
847 /* GetClassLongPtr returns that both the Unicode and ANSI wndproc */
848 ok(!IS_WNDPROC_HANDLE(GetClassLongPtrA(hwnd, GCLP_WNDPROC)), "Edit control class should have a Unicode wndproc\n");
849 ok(!IS_WNDPROC_HANDLE(GetClassLongPtrW(hwnd, GCLP_WNDPROC)), "Edit control class should have a ANSI wndproc\n");
850 /* But GetWindowLongPtr returns only a handle for the Unicode one */
851 ok(!IS_WNDPROC_HANDLE(GetWindowLongPtrA(hwnd, GWLP_WNDPROC)), "Edit control shouldn't return an A wndproc handle\n");
852 ok(IS_WNDPROC_HANDLE(GetWindowLongPtrW(hwnd, GWLP_WNDPROC)), "Edit control should return a wndproc handle\n");
853 CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
854 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
855 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
856 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
857 CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
858 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
860 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
861 ok(memcmp(buf, classW, sizeof(classW)) == 0, "WM_GETTEXT invalid return\n");
863 oldproc = (WNDPROC)SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)ClassTest_WndProc);
864 SetWindowTextW(hwnd, unistring);
865 CallWindowProcW((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
866 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
867 CallWindowProcA((WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
868 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
869 CallWindowProcW((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
870 ok(memcmp(buf, unistring, sizeof(unistring)) == 0, "WM_GETTEXT invalid return\n");
872 SetWindowTextW(hwnd, classW);
873 CallWindowProcA((WNDPROC)GetWindowLongPtrA(hwnd, GWLP_WNDPROC), hwnd, WM_GETTEXT, 120, (LPARAM)buf);
874 ok(memcmp(buf, classA, sizeof(classA)) == 0, "WM_GETTEXT invalid return\n");
876 SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)oldproc);
878 DestroyWindow(hwnd);
882 static LRESULT WINAPI TestDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
884 return DefDlgProcA(hWnd, uMsg, wParam, lParam);
887 static BOOL RegisterTestDialog(HINSTANCE hInstance)
889 WNDCLASSEXA wcx;
890 ATOM atom = 0;
892 ZeroMemory(&wcx, sizeof(WNDCLASSEXA));
893 wcx.cbSize = sizeof(wcx);
894 wcx.lpfnWndProc = TestDlgProc;
895 wcx.cbClsExtra = 0;
896 wcx.cbWndExtra = DLGWINDOWEXTRA;
897 wcx.hInstance = hInstance;
898 wcx.hIcon = LoadIconA(NULL, (LPCSTR)IDI_APPLICATION);
899 wcx.hCursor = LoadCursorA(NULL, (LPCSTR)IDC_ARROW);
900 wcx.hbrBackground = GetStockObject(WHITE_BRUSH);
901 wcx.lpszClassName = "TestDialog";
902 wcx.lpszMenuName = "TestDialog";
903 wcx.hIconSm = LoadImageA(hInstance, (LPCSTR)MAKEINTRESOURCE(5), IMAGE_ICON,
904 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
905 LR_DEFAULTCOLOR);
907 atom = RegisterClassExA(&wcx);
908 ok(atom != 0, "RegisterClassEx returned 0\n");
910 return atom;
913 /* test registering a dialog box created by using the CLASS directive in a
914 resource file, then test creating the dialog using CreateDialogParam. */
915 static void CreateDialogParamTest(HINSTANCE hInstance)
917 HWND hWndMain;
919 if (RegisterTestDialog(hInstance))
921 hWndMain = CreateDialogParamA(hInstance, "CLASS_TEST_DIALOG", NULL, 0, 0);
922 ok(hWndMain != NULL, "CreateDialogParam returned NULL\n");
923 ShowWindow(hWndMain, SW_SHOW);
924 DestroyWindow(hWndMain);
928 static const struct
930 const char name[9];
931 int value;
932 int badvalue;
933 } extra_values[] =
935 {"#32770",30,30}, /* Dialog */
936 #ifdef _WIN64
937 {"Edit",8,8},
938 #else
939 {"Edit",6,8}, /* Windows XP 64-bit returns 8 also to 32-bit applications */
940 #endif
943 static void test_extra_values(void)
945 int i;
946 for(i = 0; i < ARRAY_SIZE(extra_values); i++)
948 WNDCLASSEXA wcx;
949 BOOL ret = GetClassInfoExA(NULL,extra_values[i].name,&wcx);
951 ok( ret, "GetClassInfo (0) failed for global class %s\n", extra_values[i].name);
952 if (!ret) continue;
953 ok(extra_values[i].value == wcx.cbWndExtra || broken(extra_values[i].badvalue == wcx.cbWndExtra),
954 "expected %d, got %d\n", extra_values[i].value, wcx.cbWndExtra);
958 static void test_GetClassInfo(void)
960 static const WCHAR staticW[] = {'s','t','a','t','i','c',0};
961 WNDCLASSA wc;
962 WNDCLASSEXA wcx;
963 BOOL ret;
965 SetLastError(0xdeadbeef);
966 ret = GetClassInfoA(0, "static", &wc);
967 ok(ret, "GetClassInfoA() error %d\n", GetLastError());
969 if (0) { /* crashes under XP */
970 SetLastError(0xdeadbeef);
971 ret = GetClassInfoA(0, "static", NULL);
972 ok(ret, "GetClassInfoA() error %d\n", GetLastError());
974 SetLastError(0xdeadbeef);
975 ret = GetClassInfoW(0, staticW, NULL);
976 ok(ret, "GetClassInfoW() error %d\n", GetLastError());
979 wcx.cbSize = sizeof(wcx);
980 SetLastError(0xdeadbeef);
981 ret = GetClassInfoExA(0, "static", &wcx);
982 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
984 SetLastError(0xdeadbeef);
985 ret = GetClassInfoExA(0, "static", NULL);
986 ok(!ret, "GetClassInfoExA() should fail\n");
987 ok(GetLastError() == ERROR_NOACCESS ||
988 broken(GetLastError() == 0xdeadbeef), /* win9x */
989 "expected ERROR_NOACCESS, got %d\n", GetLastError());
991 SetLastError(0xdeadbeef);
992 ret = GetClassInfoExW(0, staticW, NULL);
993 ok(!ret, "GetClassInfoExW() should fail\n");
994 ok(GetLastError() == ERROR_NOACCESS ||
995 broken(GetLastError() == 0xdeadbeef) /* NT4 */ ||
996 broken(GetLastError() == ERROR_CALL_NOT_IMPLEMENTED), /* win9x */
997 "expected ERROR_NOACCESS, got %d\n", GetLastError());
999 wcx.cbSize = 0;
1000 wcx.lpfnWndProc = NULL;
1001 SetLastError(0xdeadbeef);
1002 ret = GetClassInfoExA(0, "static", &wcx);
1003 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
1004 ok(GetLastError() == 0xdeadbeef, "Unexpected error code %d\n", GetLastError());
1005 ok(wcx.cbSize == 0, "expected 0, got %u\n", wcx.cbSize);
1006 ok(wcx.lpfnWndProc != NULL, "got null proc\n");
1008 wcx.cbSize = sizeof(wcx) - 1;
1009 wcx.lpfnWndProc = NULL;
1010 SetLastError(0xdeadbeef);
1011 ret = GetClassInfoExA(0, "static", &wcx);
1012 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
1013 ok(wcx.cbSize == sizeof(wcx) - 1, "expected sizeof(wcx)-1, got %u\n", wcx.cbSize);
1014 ok(wcx.lpfnWndProc != NULL, "got null proc\n");
1016 wcx.cbSize = sizeof(wcx) + 1;
1017 wcx.lpfnWndProc = NULL;
1018 SetLastError(0xdeadbeef);
1019 ret = GetClassInfoExA(0, "static", &wcx);
1020 ok(ret, "GetClassInfoExA() error %d\n", GetLastError());
1021 ok(wcx.cbSize == sizeof(wcx) + 1, "expected sizeof(wcx)+1, got %u\n", wcx.cbSize);
1022 ok(wcx.lpfnWndProc != NULL, "got null proc\n");
1025 static void test_icons(void)
1027 WNDCLASSEXW wcex, ret_wcex;
1028 WCHAR cls_name[] = {'I','c','o','n','T','e','s','t','C','l','a','s','s',0};
1029 HWND hwnd;
1030 HINSTANCE hinst = GetModuleHandleW(0);
1031 HICON hsmicon, hsmallnew;
1032 ICONINFO icinf;
1034 memset(&wcex, 0, sizeof wcex);
1035 wcex.cbSize = sizeof wcex;
1036 wcex.lpfnWndProc = ClassTest_WndProc;
1037 wcex.hIcon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
1038 wcex.hInstance = hinst;
1039 wcex.lpszClassName = cls_name;
1040 ok(RegisterClassExW(&wcex), "RegisterClassExW returned 0\n");
1041 hwnd = CreateWindowExW(0, cls_name, NULL, WS_OVERLAPPEDWINDOW,
1042 0, 0, 0, 0, NULL, NULL, hinst, 0);
1043 ok(hwnd != NULL, "Window was not created\n");
1045 ok(GetClassInfoExW(hinst, cls_name, &ret_wcex), "Class info was not retrieved\n");
1046 ok(wcex.hIcon == ret_wcex.hIcon, "Icons don't match\n");
1047 ok(ret_wcex.hIconSm != NULL, "hIconSm should be non-zero handle\n");
1049 hsmicon = (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM);
1050 ok(hsmicon != NULL, "GetClassLong should return non-zero handle\n");
1052 ok(SendMessageA(hwnd, WM_GETICON, ICON_BIG, 0) == 0,
1053 "WM_GETICON with ICON_BIG should not return the class icon\n");
1054 ok(SendMessageA(hwnd, WM_GETICON, ICON_SMALL, 0) == 0,
1055 "WM_GETICON with ICON_SMALL should not return the class icon\n");
1056 ok(SendMessageA(hwnd, WM_GETICON, ICON_SMALL2, 0) == 0,
1057 "WM_GETICON with ICON_SMALL2 should not return the class icon\n");
1059 hsmallnew = CopyImage(wcex.hIcon, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
1060 GetSystemMetrics(SM_CYSMICON), 0);
1061 ok(!SetClassLongPtrW(hwnd, GCLP_HICONSM, (LONG_PTR)hsmallnew),
1062 "Previous hIconSm should be zero\n");
1063 ok(hsmallnew == (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM),
1064 "Should return explicitly assigned small icon\n");
1065 ok(!GetIconInfo(hsmicon, &icinf), "Previous small icon should be destroyed\n");
1067 SetClassLongPtrW(hwnd, GCLP_HICONSM, 0);
1068 hsmicon = (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM);
1069 ok( hsmicon != NULL, "GetClassLong should return non-zero handle\n");
1071 SetClassLongPtrW(hwnd, GCLP_HICON, 0);
1072 ok(!GetClassLongPtrW(hwnd, GCLP_HICONSM), "GetClassLong should return zero handle\n");
1074 SetClassLongPtrW(hwnd, GCLP_HICON, (LONG_PTR)LoadIconW(NULL, (LPCWSTR)IDI_QUESTION));
1075 hsmicon = (HICON)GetClassLongPtrW(hwnd, GCLP_HICONSM);
1076 ok(hsmicon != NULL, "GetClassLong should return non-zero handle\n");
1077 UnregisterClassW(cls_name, hinst);
1078 ok(GetIconInfo(hsmicon, &icinf), "Icon should NOT be destroyed\n");
1080 DestroyIcon(hsmallnew);
1081 DestroyWindow(hwnd);
1084 static void create_manifest_file(const char *filename, const char *manifest)
1086 WCHAR path[MAX_PATH];
1087 HANDLE file;
1088 DWORD size;
1090 MultiByteToWideChar( CP_ACP, 0, filename, -1, path, MAX_PATH );
1091 file = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1092 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
1093 WriteFile(file, manifest, strlen(manifest), &size, NULL);
1094 CloseHandle(file);
1097 static HANDLE create_test_actctx(const char *file)
1099 WCHAR path[MAX_PATH];
1100 ACTCTXW actctx;
1101 HANDLE handle;
1103 MultiByteToWideChar(CP_ACP, 0, file, -1, path, MAX_PATH);
1104 memset(&actctx, 0, sizeof(ACTCTXW));
1105 actctx.cbSize = sizeof(ACTCTXW);
1106 actctx.lpSource = path;
1108 handle = CreateActCtxW(&actctx);
1109 ok(handle != INVALID_HANDLE_VALUE, "failed to create context, error %u\n", GetLastError());
1111 ok(actctx.cbSize == sizeof(actctx), "cbSize=%d\n", actctx.cbSize);
1112 ok(actctx.dwFlags == 0, "dwFlags=%d\n", actctx.dwFlags);
1113 ok(actctx.lpSource == path, "lpSource=%p\n", actctx.lpSource);
1114 ok(actctx.wProcessorArchitecture == 0, "wProcessorArchitecture=%d\n", actctx.wProcessorArchitecture);
1115 ok(actctx.wLangId == 0, "wLangId=%d\n", actctx.wLangId);
1116 ok(actctx.lpAssemblyDirectory == NULL, "lpAssemblyDirectory=%p\n", actctx.lpAssemblyDirectory);
1117 ok(actctx.lpResourceName == NULL, "lpResourceName=%p\n", actctx.lpResourceName);
1118 ok(actctx.lpApplicationName == NULL, "lpApplicationName=%p\n", actctx.lpApplicationName);
1119 ok(actctx.hModule == NULL, "hModule=%p\n", actctx.hModule);
1121 return handle;
1123 static void test_comctl32_class( const char *name )
1125 WNDCLASSA wcA;
1126 WNDCLASSW wcW;
1127 BOOL ret;
1128 HMODULE module;
1129 WCHAR nameW[20];
1130 HWND hwnd;
1132 if (name[0] == '!')
1134 char path[MAX_PATH];
1135 ULONG_PTR cookie;
1136 HANDLE context;
1138 name++;
1140 GetTempPathA(ARRAY_SIZE(path), path);
1141 strcat(path, "comctl32_class.manifest");
1143 create_manifest_file(path, comctl32_manifest);
1144 context = create_test_actctx(path);
1145 ret = DeleteFileA(path);
1146 ok(ret, "Failed to delete manifest file, error %d.\n", GetLastError());
1148 module = GetModuleHandleA( "comctl32" );
1149 ok( !module, "comctl32 already loaded\n" );
1151 ret = ActivateActCtx(context, &cookie);
1152 ok(ret, "Failed to activate context.\n");
1154 /* Some systems load modules during context activation. In this case skip the rest of the test. */
1155 module = GetModuleHandleA( "comctl32" );
1156 ok( !module || broken(module != NULL) /* Vista/Win7 */, "comctl32 already loaded\n" );
1157 if (module)
1159 win_skip("Module loaded during context activation. Skipping tests.\n");
1160 goto skiptest;
1163 ret = GetClassInfoA( 0, name, &wcA );
1164 ok( ret || broken(!ret) /* WinXP */, "GetClassInfoA failed for %s\n", name );
1165 if (!ret)
1166 goto skiptest;
1168 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, ARRAY_SIZE(nameW));
1169 ret = GetClassInfoW( 0, nameW, &wcW );
1170 ok( ret, "GetClassInfoW failed for %s\n", name );
1171 module = GetModuleHandleA( "comctl32" );
1172 ok( module != 0, "comctl32 not loaded\n" );
1173 FreeLibrary( module );
1174 module = GetModuleHandleA( "comctl32" );
1175 ok( !module || broken(module != NULL) /* Vista */, "comctl32 still loaded\n" );
1176 hwnd = CreateWindowA( name, "test", WS_OVERLAPPEDWINDOW, 0, 0, 10, 10, NULL, NULL, NULL, 0 );
1177 ok( hwnd != 0, "failed to create window for %s\n", name );
1178 module = GetModuleHandleA( "comctl32" );
1179 ok( module != 0, "comctl32 not loaded\n" );
1180 DestroyWindow( hwnd );
1182 skiptest:
1183 ret = DeactivateActCtx(0, cookie);
1184 ok(ret, "Failed to deactivate context.\n");
1185 ReleaseActCtx(context);
1187 else
1189 module = GetModuleHandleA( "comctl32" );
1190 ok( !module, "comctl32 already loaded\n" );
1191 ret = GetClassInfoA( 0, name, &wcA );
1192 ok( ret || broken(!ret) /* <= winxp */, "GetClassInfoA failed for %s\n", name );
1193 if (!ret) return;
1194 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, ARRAY_SIZE(nameW));
1195 ret = GetClassInfoW( 0, nameW, &wcW );
1196 ok( ret, "GetClassInfoW failed for %s\n", name );
1197 module = GetModuleHandleA( "comctl32" );
1198 ok( module != 0, "comctl32 not loaded\n" );
1199 FreeLibrary( module );
1200 module = GetModuleHandleA( "comctl32" );
1201 ok( !module, "comctl32 still loaded\n" );
1202 hwnd = CreateWindowA( name, "test", WS_OVERLAPPEDWINDOW, 0, 0, 10, 10, NULL, NULL, NULL, 0 );
1203 ok( hwnd != 0, "failed to create window for %s\n", name );
1204 module = GetModuleHandleA( "comctl32" );
1205 ok( module != 0, "comctl32 not loaded\n" );
1206 DestroyWindow( hwnd );
1210 /* verify that comctl32 classes are automatically loaded by user32 */
1211 static void test_comctl32_classes(void)
1213 char path_name[MAX_PATH];
1214 PROCESS_INFORMATION info;
1215 STARTUPINFOA startup;
1216 char **argv;
1217 int i;
1219 static const char *classes[] =
1221 ANIMATE_CLASSA,
1222 WC_COMBOBOXEXA,
1223 DATETIMEPICK_CLASSA,
1224 WC_HEADERA,
1225 HOTKEY_CLASSA,
1226 WC_IPADDRESSA,
1227 WC_LISTVIEWA,
1228 MONTHCAL_CLASSA,
1229 WC_NATIVEFONTCTLA,
1230 WC_PAGESCROLLERA,
1231 PROGRESS_CLASSA,
1232 REBARCLASSNAMEA,
1233 STATUSCLASSNAMEA,
1234 "SysLink",
1235 WC_TABCONTROLA,
1236 TOOLBARCLASSNAMEA,
1237 TOOLTIPS_CLASSA,
1238 TRACKBAR_CLASSA,
1239 WC_TREEVIEWA,
1240 UPDOWN_CLASSA,
1241 "!Button",
1242 "!Edit",
1243 "!Static",
1244 "!Listbox",
1245 "!ComboBox",
1246 "!ComboLBox",
1249 winetest_get_mainargs( &argv );
1250 for (i = 0; i < ARRAY_SIZE(classes); i++)
1252 memset( &startup, 0, sizeof(startup) );
1253 startup.cb = sizeof( startup );
1254 sprintf( path_name, "%s class %s", argv[0], classes[i] );
1255 ok( CreateProcessA( NULL, path_name, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info ),
1256 "CreateProcess failed.\n" );
1257 winetest_wait_child_process( info.hProcess );
1258 CloseHandle( info.hProcess );
1259 CloseHandle( info.hThread );
1263 static void test_IME(void)
1265 static const WCHAR ime_classW[] = {'I','M','E',0};
1267 char module_name[MAX_PATH], *ptr;
1268 MEMORY_BASIC_INFORMATION mbi;
1269 WNDCLASSW wnd_classw;
1270 WNDCLASSA wnd_class;
1271 SIZE_T size;
1272 BOOL ret;
1274 if (!GetProcAddress(GetModuleHandleA("user32.dll"), "BroadcastSystemMessageExA"))
1276 win_skip("BroadcastSystemMessageExA not available, skipping IME class test\n");
1277 return;
1280 ok(GetModuleHandleA("imm32") != 0, "imm32.dll is not loaded\n");
1282 ret = GetClassInfoA(NULL, "IME", &wnd_class);
1283 ok(ret, "GetClassInfo failed: %d\n", GetLastError());
1285 size = VirtualQuery(wnd_class.lpfnWndProc, &mbi, sizeof(mbi));
1286 ok(size == sizeof(mbi), "VirtualQuery returned %ld\n", size);
1287 if (size == sizeof(mbi)) {
1288 size = GetModuleFileNameA(mbi.AllocationBase, module_name, sizeof(module_name));
1289 ok(size, "GetModuleFileName failed\n");
1290 for (ptr = module_name+size-1; ptr > module_name; ptr--)
1291 if (*ptr == '\\' || *ptr == '/') break;
1292 if (*ptr == '\\' || *ptr=='/') ptr++;
1293 ok(!lstrcmpiA(ptr, "user32.dll") || !lstrcmpiA(ptr, "ntdll.dll"), "IME window proc implemented in %s\n", ptr);
1296 ret = GetClassInfoW(NULL, ime_classW, &wnd_classw);
1297 ok(ret, "GetClassInfo failed: %d\n", GetLastError());
1299 size = VirtualQuery(wnd_classw.lpfnWndProc, &mbi, sizeof(mbi));
1300 ok(size == sizeof(mbi), "VirtualQuery returned %ld\n", size);
1301 size = GetModuleFileNameA(mbi.AllocationBase, module_name, sizeof(module_name));
1302 ok(size, "GetModuleFileName failed\n");
1303 for (ptr = module_name+size-1; ptr > module_name; ptr--)
1304 if (*ptr == '\\' || *ptr == '/') break;
1305 if (*ptr == '\\' || *ptr=='/') ptr++;
1306 ok(!lstrcmpiA(ptr, "user32.dll") || !lstrcmpiA(ptr, "ntdll.dll"), "IME window proc implemented in %s\n", ptr);
1309 static void test_actctx_classes(void)
1311 static const char main_manifest[] =
1312 "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\">"
1313 "<assemblyIdentity version=\"4.3.2.1\" name=\"Wine.WndClass.Test\" type=\"win32\" />"
1314 "<file name=\"file.exe\">"
1315 "<windowClass>MyTestClass</windowClass>"
1316 "</file>"
1317 "</assembly>";
1318 static const char *testclass = "MyTestClass";
1319 WNDCLASSA wc;
1320 ULONG_PTR cookie;
1321 HANDLE context;
1322 BOOL ret;
1323 ATOM class;
1324 HINSTANCE hinst;
1325 char buff[64];
1326 HWND hwnd, hwnd2;
1327 char path[MAX_PATH];
1329 GetTempPathA(ARRAY_SIZE(path), path);
1330 strcat(path, "actctx_classes.manifest");
1332 create_manifest_file(path, main_manifest);
1333 context = create_test_actctx(path);
1334 ret = DeleteFileA(path);
1335 ok(ret, "Failed to delete manifest file, error %d.\n", GetLastError());
1337 ret = ActivateActCtx(context, &cookie);
1338 ok(ret, "Failed to activate context.\n");
1340 memset(&wc, 0, sizeof(wc));
1341 wc.lpfnWndProc = ClassTest_WndProc;
1342 wc.hIcon = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
1343 wc.lpszClassName = testclass;
1345 hinst = GetModuleHandleW(0);
1347 ret = GetClassInfoA(hinst, testclass, &wc);
1348 ok(!ret, "Expected failure.\n");
1350 class = RegisterClassA(&wc);
1351 ok(class != 0, "Failed to register class.\n");
1353 /* Class info is available by versioned and regular names. */
1354 ret = GetClassInfoA(hinst, testclass, &wc);
1355 ok(ret, "Failed to get class info.\n");
1357 hwnd = CreateWindowExA(0, testclass, "test", 0, 0, 0, 0, 0, 0, 0, hinst, 0);
1358 ok(hwnd != NULL, "Failed to create a window.\n");
1360 hwnd2 = FindWindowExA(NULL, NULL, "MyTestClass", NULL);
1361 ok(hwnd2 == hwnd, "Failed to find test window.\n");
1363 hwnd2 = FindWindowExA(NULL, NULL, "4.3.2.1!MyTestClass", NULL);
1364 ok(hwnd2 == NULL, "Unexpected find result %p.\n", hwnd2);
1366 ret = GetClassNameA(hwnd, buff, sizeof(buff));
1367 ok(ret, "Failed to get class name.\n");
1368 ok(!strcmp(buff, testclass), "Unexpected class name.\n");
1370 ret = GetClassInfoA(hinst, "4.3.2.1!MyTestClass", &wc);
1371 ok(ret, "Failed to get class info.\n");
1373 ret = UnregisterClassA(testclass, hinst);
1374 ok(!ret, "Failed to unregister class.\n");
1376 ret = DeactivateActCtx(0, cookie);
1377 ok(ret, "Failed to deactivate context.\n");
1379 ret = GetClassInfoA(hinst, testclass, &wc);
1380 ok(!ret, "Unexpected ret val %d.\n", ret);
1382 ret = GetClassInfoA(hinst, "4.3.2.1!MyTestClass", &wc);
1383 ok(ret, "Failed to get class info.\n");
1385 ret = GetClassNameA(hwnd, buff, sizeof(buff));
1386 ok(ret, "Failed to get class name.\n");
1387 ok(!strcmp(buff, testclass), "Unexpected class name.\n");
1389 DestroyWindow(hwnd);
1391 hwnd = CreateWindowExA(0, "4.3.2.1!MyTestClass", "test", 0, 0, 0, 0, 0, 0, 0, hinst, 0);
1392 ok(hwnd != NULL, "Failed to create a window.\n");
1394 hwnd2 = FindWindowExA(NULL, NULL, "MyTestClass", NULL);
1395 ok(hwnd2 == hwnd, "Failed to find test window.\n");
1397 hwnd2 = FindWindowExA(NULL, NULL, "4.3.2.1!MyTestClass", NULL);
1398 ok(hwnd2 == NULL, "Unexpected find result %p.\n", hwnd2);
1400 DestroyWindow(hwnd);
1402 ret = UnregisterClassA("MyTestClass", hinst);
1403 ok(!ret, "Unexpected ret value %d.\n", ret);
1405 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1406 ok(ret, "Failed to unregister class.\n");
1408 /* Register versioned class without active context. */
1409 wc.lpszClassName = "4.3.2.1!MyTestClass";
1410 class = RegisterClassA(&wc);
1411 ok(class != 0, "Failed to register class.\n");
1413 ret = ActivateActCtx(context, &cookie);
1414 ok(ret, "Failed to activate context.\n");
1416 wc.lpszClassName = "MyTestClass";
1417 class = RegisterClassA(&wc);
1418 ok(class == 0, "Expected failure.\n");
1420 ret = DeactivateActCtx(0, cookie);
1421 ok(ret, "Failed to deactivate context.\n");
1423 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1424 ok(ret, "Failed to unregister class.\n");
1426 /* Only versioned name is registered. */
1427 ret = ActivateActCtx(context, &cookie);
1428 ok(ret, "Failed to activate context.\n");
1430 wc.lpszClassName = "MyTestClass";
1431 class = RegisterClassA(&wc);
1432 ok(class != 0, "Failed to register class\n");
1434 ret = DeactivateActCtx(0, cookie);
1435 ok(ret, "Failed to deactivate context.\n");
1437 ret = GetClassInfoA(hinst, "MyTestClass", &wc);
1438 ok(!ret, "Expected failure.\n");
1440 ret = GetClassInfoA(hinst, "4.3.2.1!MyTestClass", &wc);
1441 ok(ret, "Failed to get class info.\n");
1443 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1444 ok(ret, "Failed to unregister class.\n");
1446 /* Register regular name first, it's not considered when versioned name is registered. */
1447 wc.lpszClassName = "MyTestClass";
1448 class = RegisterClassA(&wc);
1449 ok(class != 0, "Failed to register class.\n");
1451 ret = ActivateActCtx(context, &cookie);
1452 ok(ret, "Failed to activate context.\n");
1454 wc.lpszClassName = "MyTestClass";
1455 class = RegisterClassA(&wc);
1456 ok(class != 0, "Failed to register class.\n");
1458 ret = DeactivateActCtx(0, cookie);
1459 ok(ret, "Failed to deactivate context.\n");
1461 ret = UnregisterClassA("4.3.2.1!MyTestClass", hinst);
1462 ok(ret, "Failed to unregister class.\n");
1464 ret = UnregisterClassA("MyTestClass", hinst);
1465 ok(ret, "Failed to unregister class.\n");
1467 ReleaseActCtx(context);
1470 START_TEST(class)
1472 char **argv;
1473 HANDLE hInstance = GetModuleHandleA( NULL );
1474 int argc = winetest_get_mainargs( &argv );
1476 if (argc >= 3)
1478 test_comctl32_class( argv[2] );
1479 return;
1482 test_IME();
1483 test_GetClassInfo();
1484 test_extra_values();
1486 if (!GetModuleHandleW(0))
1488 trace("Class test is incompatible with Win9x implementation, skipping\n");
1489 return;
1492 ClassTest(hInstance,FALSE);
1493 ClassTest(hInstance,TRUE);
1494 CreateDialogParamTest(hInstance);
1495 test_styles();
1496 test_builtinproc();
1497 test_icons();
1498 test_comctl32_classes();
1499 test_actctx_classes();
1501 /* this test unregisters the Button class so it should be executed at the end */
1502 test_instances();