~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/user32/class.c

Version: ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Window classes functions
  3  *
  4  * Copyright 1993, 1996, 2003 Alexandre Julliard
  5  * Copyright 1998 Juergen Schmied (jsch)
  6  *
  7  * This library is free software; you can redistribute it and/or
  8  * modify it under the terms of the GNU Lesser General Public
  9  * License as published by the Free Software Foundation; either
 10  * version 2.1 of the License, or (at your option) any later version.
 11  *
 12  * This library is distributed in the hope that it will be useful,
 13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15  * Lesser General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU Lesser General Public
 18  * License along with this library; if not, write to the Free Software
 19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 20  */
 21 
 22 #include "config.h"
 23 #include "wine/port.h"
 24 
 25 #include <assert.h>
 26 #include <stdarg.h>
 27 #include <stdlib.h>
 28 #include <string.h>
 29 
 30 #include "winerror.h"
 31 #include "windef.h"
 32 #include "winbase.h"
 33 #include "wingdi.h"
 34 #include "wine/unicode.h"
 35 #include "win.h"
 36 #include "user_private.h"
 37 #include "controls.h"
 38 #include "wine/server.h"
 39 #include "wine/list.h"
 40 #include "wine/debug.h"
 41 
 42 WINE_DEFAULT_DEBUG_CHANNEL(class);
 43 
 44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
 45 
 46 typedef struct tagCLASS
 47 {
 48     struct list      entry;         /* Entry in class list */
 49     UINT             style;         /* Class style */
 50     BOOL             local;         /* Local class? */
 51     WNDPROC          winproc;       /* Window procedure */
 52     INT              cbClsExtra;    /* Class extra bytes */
 53     INT              cbWndExtra;    /* Window extra bytes */
 54     LPWSTR           menuName;      /* Default menu name (Unicode followed by ASCII) */
 55     struct dce      *dce;           /* Opaque pointer to class DCE */
 56     HINSTANCE        hInstance;     /* Module that created the task */
 57     HICON            hIcon;         /* Default icon */
 58     HICON            hIconSm;       /* Default small icon */
 59     HCURSOR          hCursor;       /* Default cursor */
 60     HBRUSH           hbrBackground; /* Default background */
 61     ATOM             atomName;      /* Name of the class */
 62     WCHAR            name[MAX_ATOM_LEN + 1];
 63 } CLASS;
 64 
 65 static struct list class_list = LIST_INIT( class_list );
 66 
 67 #define CLASS_OTHER_PROCESS ((CLASS *)1)
 68 
 69 /***********************************************************************
 70  *           get_class_ptr
 71  */
 72 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
 73 {
 74     WND *ptr = WIN_GetPtr( hwnd );
 75 
 76     if (ptr)
 77     {
 78         if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
 79         if (!write_access) return CLASS_OTHER_PROCESS;
 80 
 81         /* modifying classes in other processes is not allowed */
 82         if (ptr == WND_DESKTOP || IsWindow( hwnd ))
 83         {
 84             SetLastError( ERROR_ACCESS_DENIED );
 85             return NULL;
 86         }
 87     }
 88     SetLastError( ERROR_INVALID_WINDOW_HANDLE );
 89     return NULL;
 90 }
 91 
 92 
 93 /***********************************************************************
 94  *           release_class_ptr
 95  */
 96 static inline void release_class_ptr( CLASS *ptr )
 97 {
 98     USER_Unlock();
 99 }
100 
101 
102 /***********************************************************************
103  *           get_int_atom_value
104  */
105 ATOM get_int_atom_value( LPCWSTR name )
106 {
107     UINT ret = 0;
108 
109     if (IS_INTRESOURCE(name)) return LOWORD(name);
110     if (*name++ != '#') return 0;
111     while (*name)
112     {
113         if (*name < '' || *name > '9') return 0;
114         ret = ret * 10 + *name++ - '';
115         if (ret > 0xffff) return 0;
116     }
117     return ret;
118 }
119 
120 
121 /***********************************************************************
122  *           set_server_info
123  *
124  * Set class info with the wine server.
125  */
126 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
127 {
128     BOOL ret;
129 
130     SERVER_START_REQ( set_class_info )
131     {
132         req->window = hwnd;
133         req->extra_offset = -1;
134         switch(offset)
135         {
136         case GCW_ATOM:
137             req->flags = SET_CLASS_ATOM;
138             req->atom = newval;
139         case GCL_STYLE:
140             req->flags = SET_CLASS_STYLE;
141             req->style = newval;
142             break;
143         case GCL_CBWNDEXTRA:
144             req->flags = SET_CLASS_WINEXTRA;
145             req->win_extra = newval;
146             break;
147         case GCLP_HMODULE:
148             req->flags = SET_CLASS_INSTANCE;
149             req->instance = (void *)newval;
150             break;
151         default:
152             assert( offset >= 0 );
153             req->flags = SET_CLASS_EXTRA;
154             req->extra_offset = offset;
155             req->extra_size = size;
156             if ( size == sizeof(LONG) )
157             {
158                 LONG newlong = newval;
159                 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
160             }
161             else
162                 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
163             break;
164         }
165         ret = !wine_server_call_err( req );
166     }
167     SERVER_END_REQ;
168     return ret;
169 }
170 
171 
172 /***********************************************************************
173  *           CLASS_GetMenuNameA
174  *
175  * Get the menu name as a ASCII string.
176  */
177 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
178 {
179     if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
180     return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
181 }
182 
183 
184 /***********************************************************************
185  *           CLASS_GetMenuNameW
186  *
187  * Get the menu name as a Unicode string.
188  */
189 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
190 {
191     return classPtr->menuName;
192 }
193 
194 
195 /***********************************************************************
196  *           CLASS_SetMenuNameA
197  *
198  * Set the menu name in a class structure by copying the string.
199  */
200 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
201 {
202     if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
203     if (HIWORD(name))
204     {
205         DWORD lenA = strlen(name) + 1;
206         DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
207         classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
208         MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
209         memcpy( classPtr->menuName + lenW, name, lenA );
210     }
211     else classPtr->menuName = (LPWSTR)name;
212 }
213 
214 
215 /***********************************************************************
216  *           CLASS_SetMenuNameW
217  *
218  * Set the menu name in a class structure by copying the string.
219  */
220 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
221 {
222     if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
223     if (HIWORD(name))
224     {
225         DWORD lenW = strlenW(name) + 1;
226         DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
227         classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
228         memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
229         WideCharToMultiByte( CP_ACP, 0, name, lenW,
230                              (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
231     }
232     else classPtr->menuName = (LPWSTR)name;
233 }
234 
235 
236 /***********************************************************************
237  *           CLASS_FreeClass
238  *
239  * Free a class structure.
240  */
241 static void CLASS_FreeClass( CLASS *classPtr )
242 {
243     TRACE("%p\n", classPtr);
244 
245     USER_Lock();
246 
247     if (classPtr->dce) free_dce( classPtr->dce, 0 );
248     list_remove( &classPtr->entry );
249     if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
250         DeleteObject( classPtr->hbrBackground );
251     HeapFree( GetProcessHeap(), 0, classPtr->menuName );
252     HeapFree( GetProcessHeap(), 0, classPtr );
253     USER_Unlock();
254 }
255 
256 
257 /***********************************************************************
258  *           CLASS_FreeModuleClasses
259  */
260 void CLASS_FreeModuleClasses( HMODULE16 hModule )
261 {
262     struct list *ptr, *next;
263 
264     TRACE("0x%08x\n", hModule);
265 
266     USER_Lock();
267     for (ptr = list_head( &class_list ); ptr; ptr = next)
268     {
269         CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
270         next = list_next( &class_list, ptr );
271         if (class->hInstance == HINSTANCE_32(hModule))
272         {
273             BOOL ret;
274 
275             SERVER_START_REQ( destroy_class )
276             {
277                 req->atom = class->atomName;
278                 req->instance = class->hInstance;
279                 ret = !wine_server_call_err( req );
280             }
281             SERVER_END_REQ;
282             if (ret) CLASS_FreeClass( class );
283         }
284     }
285     USER_Unlock();
286 }
287 
288 
289 /***********************************************************************
290  *           CLASS_FindClass
291  *
292  * Return a pointer to the class.
293  * hinstance has been normalized by the caller.
294  */
295 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
296 {
297     struct list *ptr;
298     ATOM atom = get_int_atom_value( name );
299 
300     USER_Lock();
301 
302     LIST_FOR_EACH( ptr, &class_list )
303     {
304         CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
305         if (atom)
306         {
307             if (class->atomName != atom) continue;
308         }
309         else
310         {
311             if (!name || strcmpiW( class->name, name )) continue;
312         }
313         if (!hinstance || !class->local || class->hInstance == hinstance)
314         {
315             TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
316             return class;
317         }
318     }
319     USER_Unlock();
320     TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
321     return NULL;
322 }
323 
324 
325 /***********************************************************************
326  *           CLASS_RegisterClass
327  *
328  * The real RegisterClass() functionality.
329  */
330 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
331                                    DWORD style, INT classExtra, INT winExtra )
332 {
333     CLASS *classPtr;
334     BOOL ret;
335 
336     TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
337           debugstr_w(name), hInstance, style, classExtra, winExtra );
338 
339     /* Fix the extra bytes value */
340 
341     if (classExtra < 0 || winExtra < 0)
342     {
343          SetLastError( ERROR_INVALID_PARAMETER );
344          return NULL;
345     }
346     if (classExtra > 40)  /* Extra bytes are limited to 40 in Win32 */
347         WARN("Class extra bytes %d is > 40\n", classExtra);
348     if (winExtra > 40)    /* Extra bytes are limited to 40 in Win32 */
349         WARN("Win extra bytes %d is > 40\n", winExtra );
350 
351     classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
352     if (!classPtr) return NULL;
353 
354     classPtr->atomName = get_int_atom_value( name );
355     if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
356     else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
357 
358     SERVER_START_REQ( create_class )
359     {
360         req->local      = local;
361         req->style      = style;
362         req->instance   = hInstance;
363         req->extra      = classExtra;
364         req->win_extra  = winExtra;
365         req->client_ptr = classPtr;
366         req->atom       = classPtr->atomName;
367         if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
368         ret = !wine_server_call_err( req );
369         classPtr->atomName = reply->atom;
370     }
371     SERVER_END_REQ;
372     if (!ret)
373     {
374         HeapFree( GetProcessHeap(), 0, classPtr );
375         return NULL;
376     }
377 
378     classPtr->style       = style;
379     classPtr->local       = local;
380     classPtr->cbWndExtra  = winExtra;
381     classPtr->cbClsExtra  = classExtra;
382     classPtr->hInstance   = hInstance;
383 
384     /* Other non-null values must be set by caller */
385 
386     USER_Lock();
387     if (local) list_add_head( &class_list, &classPtr->entry );
388     else list_add_tail( &class_list, &classPtr->entry );
389     return classPtr;
390 }
391 
392 
393 /***********************************************************************
394  *           register_builtin
395  *
396  * Register a builtin control class.
397  * This allows having both ASCII and Unicode winprocs for the same class.
398  */
399 static WNDPROC register_builtin( const struct builtin_class_descr *descr )
400 {
401     CLASS *classPtr;
402 
403     if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
404                                           descr->style, 0, descr->extra ))) return 0;
405 
406     classPtr->hCursor       = LoadCursorA( 0, (LPSTR)descr->cursor );
407     classPtr->hbrBackground = descr->brush;
408     classPtr->winproc       = WINPROC_AllocProc( descr->procA, descr->procW );
409     release_class_ptr( classPtr );
410     return classPtr->winproc;
411 }
412 
413 
414 /***********************************************************************
415  *           CLASS_RegisterBuiltinClasses
416  */
417 void CLASS_RegisterBuiltinClasses(void)
418 {
419     register_builtin( &DESKTOP_builtin_class );
420     register_builtin( &BUTTON_builtin_class );
421     register_builtin( &COMBO_builtin_class );
422     register_builtin( &COMBOLBOX_builtin_class );
423     register_builtin( &DIALOG_builtin_class );
424     EDIT_winproc_handle = register_builtin( &EDIT_builtin_class );
425     register_builtin( &ICONTITLE_builtin_class );
426     register_builtin( &LISTBOX_builtin_class );
427     register_builtin( &MDICLIENT_builtin_class );
428     register_builtin( &MENU_builtin_class );
429     register_builtin( &SCROLL_builtin_class );
430     register_builtin( &STATIC_builtin_class );
431 
432     /* the DefWindowProc winprocs are magic too */
433     WINPROC_AllocProc( DefWindowProcA, DefWindowProcW );
434 }
435 
436 
437 /***********************************************************************
438  *           get_class_winproc
439  */
440 WNDPROC get_class_winproc( CLASS *class )
441 {
442     return class->winproc;
443 }
444 
445 
446 /***********************************************************************
447  *           get_class_dce
448  */
449 struct dce *get_class_dce( CLASS *class )
450 {
451     return class->dce;
452 }
453 
454 
455 /***********************************************************************
456  *           set_class_dce
457  */
458 struct dce *set_class_dce( CLASS *class, struct dce *dce )
459 {
460     if (class->dce) return class->dce;  /* already set, don't change it */
461     class->dce = dce;
462     return dce;
463 }
464 
465 
466 /***********************************************************************
467  *              RegisterClassA (USER32.@)
468  *
469  * Register a window class.
470  *
471  * RETURNS
472  *      >0: Unique identifier
473  *      0: Failure
474  */
475 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
476 {
477     WNDCLASSEXA wcex;
478 
479     wcex.cbSize        = sizeof(wcex);
480     wcex.style         = wc->style;
481     wcex.lpfnWndProc   = wc->lpfnWndProc;
482     wcex.cbClsExtra    = wc->cbClsExtra;
483     wcex.cbWndExtra    = wc->cbWndExtra;
484     wcex.hInstance     = wc->hInstance;
485     wcex.hIcon         = wc->hIcon;
486     wcex.hCursor       = wc->hCursor;
487     wcex.hbrBackground = wc->hbrBackground;
488     wcex.lpszMenuName  = wc->lpszMenuName;
489     wcex.lpszClassName = wc->lpszClassName;
490     wcex.hIconSm       = 0;
491     return RegisterClassExA( &wcex );
492 }
493 
494 
495 /***********************************************************************
496  *              RegisterClassW (USER32.@)
497  *
498  * See RegisterClassA.
499  */
500 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
501 {
502     WNDCLASSEXW wcex;
503 
504     wcex.cbSize        = sizeof(wcex);
505     wcex.style         = wc->style;
506     wcex.lpfnWndProc   = wc->lpfnWndProc;
507     wcex.cbClsExtra    = wc->cbClsExtra;
508     wcex.cbWndExtra    = wc->cbWndExtra;
509     wcex.hInstance     = wc->hInstance;
510     wcex.hIcon         = wc->hIcon;
511     wcex.hCursor       = wc->hCursor;
512     wcex.hbrBackground = wc->hbrBackground;
513     wcex.lpszMenuName  = wc->lpszMenuName;
514     wcex.lpszClassName = wc->lpszClassName;
515     wcex.hIconSm       = 0;
516     return RegisterClassExW( &wcex );
517 }
518 
519 
520 /***********************************************************************
521  *              RegisterClassExA (USER32.@)
522  */
523 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
524 {
525     ATOM atom;
526     CLASS *classPtr;
527     HINSTANCE instance;
528 
529     if (wc->hInstance == user32_module)
530     {
531         /* we can't register a class for user32 */
532         SetLastError( ERROR_INVALID_PARAMETER );
533         return 0;
534     }
535     if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
536 
537     if (!IS_INTRESOURCE(wc->lpszClassName))
538     {
539         WCHAR name[MAX_ATOM_LEN + 1];
540 
541         if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
542         classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
543                                         wc->style, wc->cbClsExtra, wc->cbWndExtra );
544     }
545     else
546     {
547         classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
548                                         !(wc->style & CS_GLOBALCLASS), wc->style,
549                                         wc->cbClsExtra, wc->cbWndExtra );
550     }
551     if (!classPtr) return 0;
552     atom = classPtr->atomName;
553 
554     TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
555           debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
556           wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
557 
558     classPtr->hIcon         = wc->hIcon;
559     classPtr->hIconSm       = wc->hIconSm;
560     classPtr->hCursor       = wc->hCursor;
561     classPtr->hbrBackground = wc->hbrBackground;
562     classPtr->winproc       = WINPROC_AllocProc( wc->lpfnWndProc, NULL );
563     CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
564     release_class_ptr( classPtr );
565     return atom;
566 }
567 
568 
569 /***********************************************************************
570  *              RegisterClassExW (USER32.@)
571  */
572 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
573 {
574     ATOM atom;
575     CLASS *classPtr;
576     HINSTANCE instance;
577 
578     if (wc->hInstance == user32_module)
579     {
580         /* we can't register a class for user32 */
581         SetLastError( ERROR_INVALID_PARAMETER );
582         return 0;
583     }
584     if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
585 
586     if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
587                                           wc->style, wc->cbClsExtra, wc->cbWndExtra )))
588         return 0;
589 
590     atom = classPtr->atomName;
591 
592     TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
593           debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
594           wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
595 
596     classPtr->hIcon         = wc->hIcon;
597     classPtr->hIconSm       = wc->hIconSm;
598     classPtr->hCursor       = wc->hCursor;
599     classPtr->hbrBackground = wc->hbrBackground;
600     classPtr->winproc       = WINPROC_AllocProc( NULL, wc->lpfnWndProc );
601     CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
602     release_class_ptr( classPtr );
603     return atom;
604 }
605 
606 
607 /***********************************************************************
608  *              UnregisterClassA (USER32.@)
609  */
610 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
611 {
612     if (!IS_INTRESOURCE(className))
613     {
614         WCHAR name[MAX_ATOM_LEN + 1];
615 
616         if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
617             return FALSE;
618         return UnregisterClassW( name, hInstance );
619     }
620     return UnregisterClassW( (LPCWSTR)className, hInstance );
621 }
622 
623 /***********************************************************************
624  *              UnregisterClassW (USER32.@)
625  */
626 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
627 {
628     CLASS *classPtr = NULL;
629 
630     SERVER_START_REQ( destroy_class )
631     {
632         req->instance = hInstance;
633         if (!(req->atom = get_int_atom_value(className)) && className)
634             wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
635         if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
636     }
637     SERVER_END_REQ;
638 
639     if (classPtr) CLASS_FreeClass( classPtr );
640     return (classPtr != NULL);
641 }
642 
643 
644 /***********************************************************************
645  *              GetClassWord (USER32.@)
646  */
647 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
648 {
649     CLASS *class;
650     WORD retvalue = 0;
651 
652     if (offset < 0) return GetClassLongA( hwnd, offset );
653 
654     if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
655 
656     if (class == CLASS_OTHER_PROCESS)
657     {
658         SERVER_START_REQ( set_class_info )
659         {
660             req->window = hwnd;
661             req->flags = 0;
662             req->extra_offset = offset;
663             req->extra_size = sizeof(retvalue);
664             if (!wine_server_call_err( req ))
665                 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
666         }
667         SERVER_END_REQ;
668         return retvalue;
669     }
670 
671     if (offset <= class->cbClsExtra - sizeof(WORD))
672         memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
673     else
674         SetLastError( ERROR_INVALID_INDEX );
675     release_class_ptr( class );
676     return retvalue;
677 }
678 
679 
680 /***********************************************************************
681  *             CLASS_GetClassLong
682  *
683  * Implementation of GetClassLong(Ptr)A/W
684  */
685 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
686                                      BOOL unicode )
687 {
688     CLASS *class;
689     ULONG_PTR retvalue = 0;
690 
691     if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
692 
693     if (class == CLASS_OTHER_PROCESS)
694     {
695         SERVER_START_REQ( set_class_info )
696         {
697             req->window = hwnd;
698             req->flags = 0;
699             req->extra_offset = (offset >= 0) ? offset : -1;
700             req->extra_size = (offset >= 0) ? size : 0;
701             if (!wine_server_call_err( req ))
702             {
703                 switch(offset)
704                 {
705                 case GCLP_HBRBACKGROUND:
706                 case GCLP_HCURSOR:
707                 case GCLP_HICON:
708                 case GCLP_HICONSM:
709                 case GCLP_WNDPROC:
710                 case GCLP_MENUNAME:
711                     FIXME( "offset %d (%s) not supported on other process window %p\n",
712                            offset, SPY_GetClassLongOffsetName(offset), hwnd );
713                     SetLastError( ERROR_INVALID_HANDLE );
714                     break;
715                 case GCL_STYLE:
716                     retvalue = reply->old_style;
717                     break;
718                 case GCL_CBWNDEXTRA:
719                     retvalue = reply->old_win_extra;
720                     break;
721                 case GCL_CBCLSEXTRA:
722                     retvalue = reply->old_extra;
723                     break;
724                 case GCLP_HMODULE:
725                     retvalue = (ULONG_PTR)reply->old_instance;
726                     break;
727                 case GCW_ATOM:
728                     retvalue = reply->old_atom;
729                     break;
730                 default:
731                     if (offset >= 0)
732                     {
733                         if (size == sizeof(DWORD))
734                         {
735                             DWORD retdword;
736                             memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
737                             retvalue = retdword;
738                         }
739                         else
740                             memcpy( &retvalue, &reply->old_extra_value,
741                                     sizeof(ULONG_PTR) );
742                     }
743                     else SetLastError( ERROR_INVALID_INDEX );
744                     break;
745                 }
746             }
747         }
748         SERVER_END_REQ;
749         return retvalue;
750     }
751 
752     if (offset >= 0)
753     {
754         if (offset <= class->cbClsExtra - size)
755         {
756             if (size == sizeof(DWORD))
757             {
758                 DWORD retdword;
759                 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
760                 retvalue = retdword;
761             }
762             else
763                 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
764         }
765         else
766             SetLastError( ERROR_INVALID_INDEX );
767         release_class_ptr( class );
768         return retvalue;
769     }
770 
771     switch(offset)
772     {
773     case GCLP_HBRBACKGROUND:
774         retvalue = (ULONG_PTR)class->hbrBackground;
775         break;
776     case GCLP_HCURSOR:
777         retvalue = (ULONG_PTR)class->hCursor;
778         break;
779     case GCLP_HICON:
780         retvalue = (ULONG_PTR)class->hIcon;
781         break;
782     case GCLP_HICONSM:
783         retvalue = (ULONG_PTR)class->hIconSm;
784         break;
785     case GCL_STYLE:
786         retvalue = class->style;
787         break;
788     case GCL_CBWNDEXTRA:
789         retvalue = class->cbWndExtra;
790         break;
791     case GCL_CBCLSEXTRA:
792         retvalue = class->cbClsExtra;
793         break;
794     case GCLP_HMODULE:
795         retvalue = (ULONG_PTR)class->hInstance;
796         break;
797     case GCLP_WNDPROC:
798         retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
799         break;
800     case GCLP_MENUNAME:
801         retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
802         if (unicode)
803             retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
804         else
805             retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
806         break;
807     case GCW_ATOM:
808         retvalue = class->atomName;
809         break;
810     default:
811         SetLastError( ERROR_INVALID_INDEX );
812         break;
813     }
814     release_class_ptr( class );
815     return retvalue;
816 }
817 
818 
819 /***********************************************************************
820  *              GetClassLongW (USER32.@)
821  */
822 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
823 {
824     return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
825 }
826 
827 
828 
829 /***********************************************************************
830  *              GetClassLongA (USER32.@)
831  */
832 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
833 {
834     return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
835 }
836 
837 
838 /***********************************************************************
839  *              SetClassWord (USER32.@)
840  */
841 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
842 {
843     CLASS *class;
844     WORD retval = 0;
845 
846     if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
847 
848     if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
849 
850     SERVER_START_REQ( set_class_info )
851     {
852         req->window = hwnd;
853         req->flags = SET_CLASS_EXTRA;
854         req->extra_offset = offset;
855         req->extra_size = sizeof(newval);
856         memcpy( &req->extra_value, &newval, sizeof(newval) );
857         if (!wine_server_call_err( req ))
858         {
859             void *ptr = (char *)(class + 1) + offset;
860             memcpy( &retval, ptr, sizeof(retval) );
861             memcpy( ptr, &newval, sizeof(newval) );
862         }
863     }
864     SERVER_END_REQ;
865     release_class_ptr( class );
866     return retval;
867 }
868 
869 
870 /***********************************************************************
871  *             CLASS_SetClassLong
872  *
873  * Implementation of SetClassLong(Ptr)A/W
874  */
875 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
876                                      UINT size, BOOL unicode )
877 {
878     CLASS *class;
879     ULONG_PTR retval = 0;
880 
881     if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
882 
883     if (offset >= 0)
884     {
885         if (set_server_info( hwnd, offset, newval, size ))
886         {
887             void *ptr = (char *)(class + 1) + offset;
888             if ( size == sizeof(LONG) )
889             {
890                 DWORD retdword;
891                 LONG newlong = newval;
892                 memcpy( &retdword, ptr, sizeof(DWORD) );
893                 memcpy( ptr, &newlong, sizeof(LONG) );
894                 retval = retdword;
895             }
896             else
897             {
898                 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
899                 memcpy( ptr, &newval, sizeof(LONG_PTR) );
900             }
901         }
902     }
903     else switch(offset)
904     {
905     case GCLP_MENUNAME:
906         if ( unicode )
907             CLASS_SetMenuNameW( class, (LPCWSTR)newval );
908         else
909             CLASS_SetMenuNameA( class, (LPCSTR)newval );
910         retval = 0;  /* Old value is now meaningless anyway */
911         break;
912     case GCLP_WNDPROC:
913         retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
914         class->winproc = WINPROC_AllocProc( unicode ? NULL : (WNDPROC)newval,
915                                             unicode ? (WNDPROC)newval : NULL );
916         break;
917     case GCLP_HBRBACKGROUND:
918         retval = (ULONG_PTR)class->hbrBackground;
919         class->hbrBackground = (HBRUSH)newval;
920         break;
921     case GCLP_HCURSOR:
922         retval = (ULONG_PTR)class->hCursor;
923         class->hCursor = (HCURSOR)newval;
924         break;
925     case GCLP_HICON:
926         retval = (ULONG_PTR)class->hIcon;
927         class->hIcon = (HICON)newval;
928         break;
929     case GCLP_HICONSM:
930         retval = (ULONG_PTR)class->hIconSm;
931         class->hIconSm = (HICON)newval;
932         break;
933     case GCL_STYLE:
934         if (!set_server_info( hwnd, offset, newval, size )) break;
935         retval = class->style;
936         class->style = newval;
937         break;
938     case GCL_CBWNDEXTRA:
939         if (!set_server_info( hwnd, offset, newval, size )) break;
940         retval = class->cbWndExtra;
941         class->cbWndExtra = newval;
942         break;
943     case GCLP_HMODULE:
944         if (!set_server_info( hwnd, offset, newval, size )) break;
945         retval = (ULONG_PTR)class->hInstance;
946         class->hInstance = (HINSTANCE)newval;
947         break;
948     case GCW_ATOM:
949         if (!set_server_info( hwnd, offset, newval, size )) break;
950         retval = class->atomName;
951         class->atomName = newval;
952         GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
953         break;
954     case GCL_CBCLSEXTRA:  /* cannot change this one */
955         SetLastError( ERROR_INVALID_PARAMETER );
956         break;
957     default:
958         SetLastError( ERROR_INVALID_INDEX );
959         break;
960     }
961     release_class_ptr( class );
962     return retval;
963 }
964 
965 
966 /***********************************************************************
967  *              SetClassLongW (USER32.@)
968  */
969