rpcrt4: Add stub for RpcMgmtEnableIdleCleanup.
[wine] / dlls / user / class.c
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/winuser16.h"
35 #include "wine/unicode.h"
36 #include "win.h"
37 #include "user_private.h"
38 #include "controls.h"
39 #include "winproc.h"
40 #include "wine/server.h"
41 #include "wine/list.h"
42 #include "wine/debug.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(class);
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     HINSTANCE        hInstance;     /* Module that created the task */
56     HICON            hIcon;         /* Default icon */
57     HICON            hIconSm;       /* Default small icon */
58     HCURSOR          hCursor;       /* Default cursor */
59     HBRUSH           hbrBackground; /* Default background */
60     ATOM             atomName;      /* Name of the class */
61 } CLASS;
62
63 static struct list class_list = LIST_INIT( class_list );
64
65 #define CLASS_OTHER_PROCESS ((CLASS *)1)
66
67 /***********************************************************************
68  *           get_class_ptr
69  */
70 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
71 {
72     WND *ptr = WIN_GetPtr( hwnd );
73
74     if (ptr)
75     {
76         if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
77         if (!write_access) return CLASS_OTHER_PROCESS;
78
79         /* modifying classes in other processes is not allowed */
80         if (ptr == WND_DESKTOP || IsWindow( hwnd ))
81         {
82             SetLastError( ERROR_ACCESS_DENIED );
83             return NULL;
84         }
85     }
86     SetLastError( ERROR_INVALID_WINDOW_HANDLE );
87     return NULL;
88 }
89
90
91 /***********************************************************************
92  *           release_class_ptr
93  */
94 inline static void release_class_ptr( CLASS *ptr )
95 {
96     USER_Unlock();
97 }
98
99
100 /***********************************************************************
101  *           set_server_info
102  *
103  * Set class info with the wine server.
104  */
105 static BOOL set_server_info( HWND hwnd, INT offset, LONG newval )
106 {
107     BOOL ret;
108
109     SERVER_START_REQ( set_class_info )
110     {
111         req->window = hwnd;
112         req->extra_offset = -1;
113         switch(offset)
114         {
115         case GCW_ATOM:
116             req->flags = SET_CLASS_ATOM;
117             req->atom = newval;
118         case GCL_STYLE:
119             req->flags = SET_CLASS_STYLE;
120             req->style = newval;
121             break;
122         case GCL_CBWNDEXTRA:
123             req->flags = SET_CLASS_WINEXTRA;
124             req->win_extra = newval;
125             break;
126         case GCLP_HMODULE:
127             req->flags = SET_CLASS_INSTANCE;
128             req->instance = (void *)newval;
129             break;
130         default:
131             assert( offset >= 0 );
132             req->flags = SET_CLASS_EXTRA;
133             req->extra_offset = offset;
134             req->extra_size = sizeof(newval);
135             memcpy( &req->extra_value, &newval, sizeof(newval) );
136             break;
137         }
138         ret = !wine_server_call_err( req );
139     }
140     SERVER_END_REQ;
141     return ret;
142 }
143
144
145 /***********************************************************************
146  *           CLASS_GetMenuNameA
147  *
148  * Get the menu name as a ASCII string.
149  */
150 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
151 {
152     if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
153     return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
154 }
155
156
157 /***********************************************************************
158  *           CLASS_GetMenuNameW
159  *
160  * Get the menu name as a Unicode string.
161  */
162 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
163 {
164     return classPtr->menuName;
165 }
166
167
168 /***********************************************************************
169  *           CLASS_SetMenuNameA
170  *
171  * Set the menu name in a class structure by copying the string.
172  */
173 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
174 {
175     if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
176     if (HIWORD(name))
177     {
178         DWORD lenA = strlen(name) + 1;
179         DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
180         classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
181         MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
182         memcpy( classPtr->menuName + lenW, name, lenA );
183     }
184     else classPtr->menuName = (LPWSTR)name;
185 }
186
187
188 /***********************************************************************
189  *           CLASS_SetMenuNameW
190  *
191  * Set the menu name in a class structure by copying the string.
192  */
193 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
194 {
195     if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
196     if (HIWORD(name))
197     {
198         DWORD lenW = strlenW(name) + 1;
199         DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
200         classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
201         memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
202         WideCharToMultiByte( CP_ACP, 0, name, lenW,
203                              (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
204     }
205     else classPtr->menuName = (LPWSTR)name;
206 }
207
208
209 /***********************************************************************
210  *           CLASS_FreeClass
211  *
212  * Free a class structure.
213  */
214 static void CLASS_FreeClass( CLASS *classPtr )
215 {
216     TRACE("%p\n", classPtr);
217
218     USER_Lock();
219
220     list_remove( &classPtr->entry );
221     if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
222         DeleteObject( classPtr->hbrBackground );
223     HeapFree( GetProcessHeap(), 0, classPtr->menuName );
224     HeapFree( GetProcessHeap(), 0, classPtr );
225     USER_Unlock();
226 }
227
228
229 /***********************************************************************
230  *           CLASS_FreeModuleClasses
231  */
232 void CLASS_FreeModuleClasses( HMODULE16 hModule )
233 {
234     struct list *ptr, *next;
235
236     TRACE("0x%08x\n", hModule);
237
238     USER_Lock();
239     for (ptr = list_head( &class_list ); ptr; ptr = next)
240     {
241         CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
242         next = list_next( &class_list, ptr );
243         if (class->hInstance == HINSTANCE_32(hModule))
244         {
245             BOOL ret;
246
247             SERVER_START_REQ( destroy_class )
248             {
249                 req->atom = class->atomName;
250                 req->instance = class->hInstance;
251                 ret = !wine_server_call_err( req );
252             }
253             SERVER_END_REQ;
254             if (ret) CLASS_FreeClass( class );
255         }
256     }
257     USER_Unlock();
258 }
259
260
261 /***********************************************************************
262  *           CLASS_FindClassByAtom
263  *
264  * Return a pointer to the class.
265  * hinstance has been normalized by the caller.
266  */
267 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
268 {
269     struct list *ptr;
270
271     USER_Lock();
272
273     LIST_FOR_EACH( ptr, &class_list )
274     {
275         CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
276         if (class->atomName != atom) continue;
277         if (!hinstance || !class->local || class->hInstance == hinstance)
278         {
279             TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
280             return class;
281         }
282     }
283     USER_Unlock();
284     TRACE("0x%04x %p -> not found\n", atom, hinstance);
285     return NULL;
286 }
287
288
289 /***********************************************************************
290  *           CLASS_RegisterClass
291  *
292  * The real RegisterClass() functionality.
293  * The atom is deleted no matter what.
294  */
295 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
296                                    DWORD style, INT classExtra, INT winExtra )
297 {
298     CLASS *classPtr;
299     BOOL ret;
300
301     TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
302           atom, hInstance, style, classExtra, winExtra );
303
304     /* Fix the extra bytes value */
305
306     if (classExtra < 0 || winExtra < 0)
307     {
308          SetLastError( ERROR_INVALID_PARAMETER );
309          return NULL;
310     }
311     if (classExtra > 40)  /* Extra bytes are limited to 40 in Win32 */
312         WARN("Class extra bytes %d is > 40\n", classExtra);
313     if (winExtra > 40)    /* Extra bytes are limited to 40 in Win32 */
314         WARN("Win extra bytes %d is > 40\n", winExtra );
315
316     classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
317     if (!classPtr)
318     {
319         GlobalDeleteAtom( atom );
320         return NULL;
321     }
322
323     SERVER_START_REQ( create_class )
324     {
325         req->local      = local;
326         req->atom       = atom;
327         req->style      = style;
328         req->instance   = hInstance;
329         req->extra      = classExtra;
330         req->win_extra  = winExtra;
331         req->client_ptr = classPtr;
332         ret = !wine_server_call_err( req );
333     }
334     SERVER_END_REQ;
335     GlobalDeleteAtom( atom );  /* the server increased the atom ref count */
336     if (!ret)
337     {
338         HeapFree( GetProcessHeap(), 0, classPtr );
339         return NULL;
340     }
341
342     classPtr->style       = style;
343     classPtr->local       = local;
344     classPtr->cbWndExtra  = winExtra;
345     classPtr->cbClsExtra  = classExtra;
346     classPtr->hInstance   = hInstance;
347     classPtr->atomName    = atom;
348
349     /* Other non-null values must be set by caller */
350
351     USER_Lock();
352     if (local) list_add_head( &class_list, &classPtr->entry );
353     else list_add_tail( &class_list, &classPtr->entry );
354     return classPtr;
355 }
356
357
358 /***********************************************************************
359  *           register_builtin
360  *
361  * Register a builtin control class.
362  * This allows having both ASCII and Unicode winprocs for the same class.
363  */
364 static CLASS *register_builtin( const struct builtin_class_descr *descr )
365 {
366     ATOM atom;
367     CLASS *classPtr;
368
369     if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
370
371     if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
372                                           descr->style, 0, descr->extra ))) return 0;
373
374     classPtr->hCursor       = LoadCursorA( 0, (LPSTR)descr->cursor );
375     classPtr->hbrBackground = descr->brush;
376     classPtr->winproc       = WINPROC_AllocProc( descr->procA, descr->procW );
377     release_class_ptr( classPtr );
378     return classPtr;
379 }
380
381
382 /***********************************************************************
383  *           CLASS_RegisterBuiltinClasses
384  */
385 void CLASS_RegisterBuiltinClasses(void)
386 {
387     extern const struct builtin_class_descr BUTTON_builtin_class;
388     extern const struct builtin_class_descr COMBO_builtin_class;
389     extern const struct builtin_class_descr COMBOLBOX_builtin_class;
390     extern const struct builtin_class_descr DIALOG_builtin_class;
391     extern const struct builtin_class_descr DESKTOP_builtin_class;
392     extern const struct builtin_class_descr EDIT_builtin_class;
393     extern const struct builtin_class_descr ICONTITLE_builtin_class;
394     extern const struct builtin_class_descr LISTBOX_builtin_class;
395     extern const struct builtin_class_descr MDICLIENT_builtin_class;
396     extern const struct builtin_class_descr MENU_builtin_class;
397     extern const struct builtin_class_descr SCROLL_builtin_class;
398     extern const struct builtin_class_descr STATIC_builtin_class;
399
400     register_builtin( &DESKTOP_builtin_class );
401     register_builtin( &BUTTON_builtin_class );
402     register_builtin( &COMBO_builtin_class );
403     register_builtin( &COMBOLBOX_builtin_class );
404     register_builtin( &DIALOG_builtin_class );
405     register_builtin( &EDIT_builtin_class );
406     register_builtin( &ICONTITLE_builtin_class );
407     register_builtin( &LISTBOX_builtin_class );
408     register_builtin( &MDICLIENT_builtin_class );
409     register_builtin( &MENU_builtin_class );
410     register_builtin( &SCROLL_builtin_class );
411     register_builtin( &STATIC_builtin_class );
412 }
413
414
415 /***********************************************************************
416  *           CLASS_AddWindow
417  *
418  * Add a new window using this class, and set the necessary
419  * information inside the window structure.
420  */
421 void CLASS_AddWindow( CLASS *class, WND *win, BOOL unicode )
422 {
423     win->class    = class;
424     win->clsStyle = class->style;
425     win->winproc  = class->winproc;
426     if (WINPROC_IsUnicode( win->winproc, unicode )) win->flags |= WIN_ISUNICODE;
427 }
428
429
430 /***********************************************************************
431  *              RegisterClassA (USER32.@)
432  *
433  * Register a window class.
434  *
435  * RETURNS
436  *      >0: Unique identifier
437  *      0: Failure
438  */
439 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
440 {
441     WNDCLASSEXA wcex;
442
443     wcex.cbSize        = sizeof(wcex);
444     wcex.style         = wc->style;
445     wcex.lpfnWndProc   = wc->lpfnWndProc;
446     wcex.cbClsExtra    = wc->cbClsExtra;
447     wcex.cbWndExtra    = wc->cbWndExtra;
448     wcex.hInstance     = wc->hInstance;
449     wcex.hIcon         = wc->hIcon;
450     wcex.hCursor       = wc->hCursor;
451     wcex.hbrBackground = wc->hbrBackground;
452     wcex.lpszMenuName  = wc->lpszMenuName;
453     wcex.lpszClassName = wc->lpszClassName;
454     wcex.hIconSm       = 0;
455     return RegisterClassExA( &wcex );
456 }
457
458
459 /***********************************************************************
460  *              RegisterClassW (USER32.@)
461  *
462  * See RegisterClassA.
463  */
464 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
465 {
466     WNDCLASSEXW wcex;
467
468     wcex.cbSize        = sizeof(wcex);
469     wcex.style         = wc->style;
470     wcex.lpfnWndProc   = wc->lpfnWndProc;
471     wcex.cbClsExtra    = wc->cbClsExtra;
472     wcex.cbWndExtra    = wc->cbWndExtra;
473     wcex.hInstance     = wc->hInstance;
474     wcex.hIcon         = wc->hIcon;
475     wcex.hCursor       = wc->hCursor;
476     wcex.hbrBackground = wc->hbrBackground;
477     wcex.lpszMenuName  = wc->lpszMenuName;
478     wcex.lpszClassName = wc->lpszClassName;
479     wcex.hIconSm       = 0;
480     return RegisterClassExW( &wcex );
481 }
482
483
484 /***********************************************************************
485  *              RegisterClassExA (USER32.@)
486  */
487 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
488 {
489     ATOM atom;
490     CLASS *classPtr;
491     HINSTANCE instance;
492
493     if (wc->hInstance == user32_module)
494     {
495         /* we can't register a class for user32 */
496         SetLastError( ERROR_INVALID_PARAMETER );
497         return 0;
498     }
499     if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
500
501     if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
502
503     if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
504                                           wc->style, wc->cbClsExtra, wc->cbWndExtra )))
505         return 0;
506
507     TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
508           atom, wc->lpfnWndProc, instance, wc->hbrBackground,
509           wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
510
511     classPtr->hIcon         = wc->hIcon;
512     classPtr->hIconSm       = wc->hIconSm;
513     classPtr->hCursor       = wc->hCursor;
514     classPtr->hbrBackground = wc->hbrBackground;
515     classPtr->winproc       = WINPROC_AllocProc( wc->lpfnWndProc, NULL );
516     CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
517     release_class_ptr( classPtr );
518     return atom;
519 }
520
521
522 /***********************************************************************
523  *              RegisterClassExW (USER32.@)
524  */
525 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
526 {
527     ATOM atom;
528     CLASS *classPtr;
529     HINSTANCE instance;
530
531     if (wc->hInstance == user32_module)
532     {
533         /* we can't register a class for user32 */
534         SetLastError( ERROR_INVALID_PARAMETER );
535         return 0;
536     }
537     if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
538
539     if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
540
541     if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
542                                           wc->style, wc->cbClsExtra, wc->cbWndExtra )))
543         return 0;
544
545     TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
546           atom, wc->lpfnWndProc, instance, wc->hbrBackground,
547           wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
548
549     classPtr->hIcon         = wc->hIcon;
550     classPtr->hIconSm       = wc->hIconSm;
551     classPtr->hCursor       = wc->hCursor;
552     classPtr->hbrBackground = wc->hbrBackground;
553     classPtr->winproc       = WINPROC_AllocProc( NULL, wc->lpfnWndProc );
554     CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
555     release_class_ptr( classPtr );
556     return atom;
557 }
558
559
560 /***********************************************************************
561  *              UnregisterClassA (USER32.@)
562  */
563 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
564 {
565     ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
566     return UnregisterClassW( MAKEINTATOMW(atom), hInstance );
567 }
568
569 /***********************************************************************
570  *              UnregisterClassW (USER32.@)
571  */
572 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
573 {
574     CLASS *classPtr = NULL;
575     ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
576
577     TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
578
579     if (!atom)
580     {
581         SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
582         return FALSE;
583     }
584
585     SERVER_START_REQ( destroy_class )
586     {
587         req->atom = atom;
588         req->instance = hInstance;
589         if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
590     }
591     SERVER_END_REQ;
592
593     if (classPtr) CLASS_FreeClass( classPtr );
594     return (classPtr != NULL);
595 }
596
597
598 /***********************************************************************
599  *              GetClassWord (USER32.@)
600  */
601 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
602 {
603     CLASS *class;
604     WORD retvalue = 0;
605
606     if (offset < 0) return GetClassLongA( hwnd, offset );
607
608     TRACE("%p %x\n",hwnd, offset);
609
610     if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
611
612     if (class == CLASS_OTHER_PROCESS)
613     {
614         SERVER_START_REQ( set_class_info )
615         {
616             req->window = hwnd;
617             req->flags = 0;
618             req->extra_offset = offset;
619             req->extra_size = sizeof(retvalue);
620             if (!wine_server_call_err( req ))
621                 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
622         }
623         SERVER_END_REQ;
624         return retvalue;
625     }
626
627     if (offset <= class->cbClsExtra - sizeof(WORD))
628         memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
629     else
630         SetLastError( ERROR_INVALID_INDEX );
631     release_class_ptr( class );
632     return retvalue;
633 }
634
635
636 /***********************************************************************
637  *              GetClassLongW (USER32.@)
638  */
639 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
640 {
641     CLASS *class;
642     DWORD retvalue = 0;
643
644     TRACE("%p %d\n", hwnd, offset);
645
646     if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
647
648     if (class == CLASS_OTHER_PROCESS)
649     {
650         SERVER_START_REQ( set_class_info )
651         {
652             req->window = hwnd;
653             req->flags = 0;
654             req->extra_offset = (offset >= 0) ? offset : -1;
655             req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
656             if (!wine_server_call_err( req ))
657             {
658                 switch(offset)
659                 {
660                 case GCLP_HBRBACKGROUND:
661                 case GCLP_HCURSOR:
662                 case GCLP_HICON:
663                 case GCLP_HICONSM:
664                 case GCLP_WNDPROC:
665                 case GCLP_MENUNAME:
666                     FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
667                     SetLastError( ERROR_INVALID_HANDLE );
668                     break;
669                 case GCL_STYLE:
670                     retvalue = reply->old_style;
671                     break;
672                 case GCL_CBWNDEXTRA:
673                     retvalue = reply->old_win_extra;
674                     break;
675                 case GCL_CBCLSEXTRA:
676                     retvalue = reply->old_extra;
677                     break;
678                 case GCLP_HMODULE:
679                     retvalue = (DWORD)reply->old_instance;
680                     break;
681                 case GCW_ATOM:
682                     retvalue = reply->old_atom;
683                     break;
684                 default:
685                     if (offset >= 0) memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
686                     else SetLastError( ERROR_INVALID_INDEX );
687                     break;
688                 }
689             }
690         }
691         SERVER_END_REQ;
692         return retvalue;
693     }
694
695     if (offset >= 0)
696     {
697         if (offset <= class->cbClsExtra - sizeof(LONG))
698             memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
699         else
700             SetLastError( ERROR_INVALID_INDEX );
701         release_class_ptr( class );
702         return retvalue;
703     }
704
705     switch(offset)
706     {
707     case GCLP_HBRBACKGROUND:
708         retvalue = (DWORD)class->hbrBackground;
709         break;
710     case GCLP_HCURSOR:
711         retvalue = (DWORD)class->hCursor;
712         break;
713     case GCLP_HICON:
714         retvalue = (DWORD)class->hIcon;
715         break;
716     case GCLP_HICONSM:
717         retvalue = (DWORD)class->hIconSm;
718         break;
719     case GCL_STYLE:
720         retvalue = (DWORD)class->style;
721         break;
722     case GCL_CBWNDEXTRA:
723         retvalue = (DWORD)class->cbWndExtra;
724         break;
725     case GCL_CBCLSEXTRA:
726         retvalue = (DWORD)class->cbClsExtra;
727         break;
728     case GCLP_HMODULE:
729         retvalue = (DWORD)class->hInstance;
730         break;
731     case GCLP_WNDPROC:
732         retvalue = (DWORD)WINPROC_GetProc( class->winproc, TRUE );
733         break;
734     case GCLP_MENUNAME:
735         retvalue = (DWORD)CLASS_GetMenuNameW( class );
736         break;
737     case GCW_ATOM:
738         retvalue = (DWORD)class->atomName;
739         break;
740     default:
741         SetLastError( ERROR_INVALID_INDEX );
742         break;
743     }
744     release_class_ptr( class );
745     return retvalue;
746 }
747
748
749 /***********************************************************************
750  *              GetClassLongA (USER32.@)
751  */
752 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
753 {
754     CLASS *class;
755     DWORD retvalue;
756
757     if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
758         return GetClassLongW( hwnd, offset );
759
760     TRACE("%p %d\n", hwnd, offset);
761
762     if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
763
764     if (class == CLASS_OTHER_PROCESS)
765     {
766         FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
767         SetLastError( ERROR_INVALID_HANDLE );
768         return 0;
769     }
770
771     if (offset == GCLP_WNDPROC)
772         retvalue = (DWORD)WINPROC_GetProc( class->winproc, FALSE );
773     else  /* GCL_MENUNAME */
774         retvalue = (DWORD)CLASS_GetMenuNameA( class );
775
776     release_class_ptr( class );
777     return retvalue;
778 }
779
780
781 /***********************************************************************
782  *              SetClassWord (USER32.@)
783  */
784 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
785 {
786     CLASS *class;
787     WORD retval = 0;
788
789     if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
790
791     TRACE("%p %d %x\n", hwnd, offset, newval);
792
793     if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
794
795     SERVER_START_REQ( set_class_info )
796     {
797         req->window = hwnd;
798         req->flags = SET_CLASS_EXTRA;
799         req->extra_offset = offset;
800         req->extra_size = sizeof(newval);
801         memcpy( &req->extra_value, &newval, sizeof(newval) );
802         if (!wine_server_call_err( req ))
803         {
804             void *ptr = (char *)(class + 1) + offset;
805             memcpy( &retval, ptr, sizeof(retval) );
806             memcpy( ptr, &newval, sizeof(newval) );
807         }
808     }
809     SERVER_END_REQ;
810     release_class_ptr( class );
811     return retval;
812 }
813
814
815 /***********************************************************************
816  *              SetClassLongW (USER32.@)
817  */
818 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
819 {
820     CLASS *class;
821     DWORD retval = 0;
822
823     TRACE("%p %d %lx\n", hwnd, offset, newval);
824
825     if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
826
827     if (offset >= 0)
828     {
829         if (set_server_info( hwnd, offset, newval ))
830         {
831             void *ptr = (char *)(class + 1) + offset;
832             memcpy( &retval, ptr, sizeof(retval) );
833             memcpy( ptr, &newval, sizeof(newval) );
834         }
835     }
836     else switch(offset)
837     {
838     case GCLP_MENUNAME:
839         CLASS_SetMenuNameW( class, (LPCWSTR)newval );
840         retval = 0;  /* Old value is now meaningless anyway */
841         break;
842     case GCLP_WNDPROC:
843         retval = (DWORD)WINPROC_GetProc( class->winproc, TRUE );
844         class->winproc = WINPROC_AllocProc( NULL, (WNDPROC)newval );
845         break;
846     case GCLP_HBRBACKGROUND:
847         retval = (DWORD)class->hbrBackground;
848         class->hbrBackground = (HBRUSH)newval;
849         break;
850     case GCLP_HCURSOR:
851         retval = (DWORD)class->hCursor;
852         class->hCursor = (HCURSOR)newval;
853         break;
854     case GCLP_HICON:
855         retval = (DWORD)class->hIcon;
856         class->hIcon = (HICON)newval;
857         break;
858     case GCLP_HICONSM:
859         retval = (DWORD)class->hIconSm;
860         class->hIconSm = (HICON)newval;
861         break;
862     case GCL_STYLE:
863         if (!set_server_info( hwnd, offset, newval )) break;
864         retval = (DWORD)class->style;
865         class->style = newval;
866         break;
867     case GCL_CBWNDEXTRA:
868         if (!set_server_info( hwnd, offset, newval )) break;
869         retval = (DWORD)class->cbWndExtra;
870         class->cbWndExtra = newval;
871         break;
872     case GCLP_HMODULE:
873         if (!set_server_info( hwnd, offset, newval )) break;
874         retval = (DWORD)class->hInstance;
875         class->hInstance = (HINSTANCE)newval;
876         break;
877     case GCW_ATOM:
878         if (!set_server_info( hwnd, offset, newval )) break;
879         retval = (DWORD)class->atomName;
880         class->atomName = newval;
881         break;
882     case GCL_CBCLSEXTRA:  /* cannot change this one */
883         SetLastError( ERROR_INVALID_PARAMETER );
884         break;
885     default:
886         SetLastError( ERROR_INVALID_INDEX );
887         break;
888     }
889     release_class_ptr( class );
890     return retval;
891 }
892
893
894 /***********************************************************************
895  *              SetClassLongA (USER32.@)
896  */
897 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
898 {
899     CLASS *class;
900     DWORD retval;
901
902     if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
903         return SetClassLongW( hwnd, offset, newval );
904
905     TRACE("%p %d %lx\n", hwnd, offset, newval);
906
907     if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
908
909     if (offset == GCLP_WNDPROC)
910     {
911         retval = (DWORD)WINPROC_GetProc( class->winproc, FALSE );
912         class->winproc = WINPROC_AllocProc( (WNDPROC)newval, NULL );
913     }
914     else  /* GCL_MENUNAME */
915     {
916         CLASS_SetMenuNameA( class, (LPCSTR)newval );
917         retval = 0;  /* Old value is now meaningless anyway */
918     }
919     release_class_ptr( class );
920     return retval;
921 }
922
923
924 /***********************************************************************
925  *              GetClassNameA (USER32.@)
926  */
927 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
928 {
929     INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
930
931     TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
932     return ret;
933 }
934
935
936 /***********************************************************************
937  *              GetClassNameW (USER32.@)
938  */
939 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
940 {
941     INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
942
943     TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
944     return ret;
945 }
946
947
948 /***********************************************************************
949  *              RealGetWindowClassA (USER32.@)
950  */
951 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
952 {
953     return GetClassNameA( hwnd, buffer, count );
954 }
955
956
957 /***********************************************************************
958  *              RealGetWindowClassW (USER32.@)
959  */
960 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
961 {
962     return GetClassNameW( hwnd, buffer, count );
963 }
964
965
966 /***********************************************************************
967  *              GetClassInfoA (USER32.@)
968  */
969 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
970 {
971     WNDCLASSEXA wcex;
972     UINT ret = GetClassInfoExA( hInstance, name, &wcex );
973
974     if (ret)
975     {
976         wc->style         = wcex.style;
977         wc->lpfnWndProc   = wcex.lpfnWndProc;
978         wc->cbClsExtra    = wcex.cbClsExtra;
979         wc->cbWndExtra    = wcex.cbWndExtra;
980         wc->hInstance     = wcex.hInstance;
981         wc->hIcon         = wcex.hIcon;
982         wc->hCursor       = wcex.hCursor;
983         wc->hbrBackground = wcex.hbrBackground;
984         wc->lpszMenuName  = wcex.lpszMenuName;
985         wc->lpszClassName = wcex.lpszClassName;
986     }
987     return ret;
988 }
989
990
991 /***********************************************************************
992  *              GetClassInfoW (USER32.@)
993  */
994 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
995 {
996     WNDCLASSEXW wcex;
997     UINT ret = GetClassInfoExW( hInstance, name, &wcex );
998
999     if (ret)
1000     {
1001         wc->style         = wcex.style;
1002         wc->lpfnWndProc   = wcex.lpfnWndProc;
1003         wc->cbClsExtra    = wcex.cbClsExtra;
1004         wc->cbWndExtra    = wcex.cbWndExtra;
1005         wc->hInstance     = wcex.hInstance;
1006         wc->hIcon         = wcex.hIcon;
1007         wc->hCursor       = wcex.hCursor;
1008         wc->hbrBackground = wcex.hbrBackground;
1009         wc->lpszMenuName  = wcex.lpszMenuName;
1010         wc->lpszClassName = wcex.lpszClassName;
1011     }
1012     return ret;
1013 }
1014
1015
1016 /***********************************************************************
1017  *              GetClassInfoExA (USER32.@)
1018  */
1019 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1020 {
1021     ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1022     CLASS *classPtr;
1023
1024     TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1025
1026     if (!hInstance) hInstance = user32_module;
1027
1028     if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1029     {
1030         SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1031         return FALSE;
1032     }
1033     wc->style         = classPtr->style;
1034     wc->lpfnWndProc   = WINPROC_GetProc( classPtr->winproc, FALSE );
1035     wc->cbClsExtra    = classPtr->cbClsExtra;
1036     wc->cbWndExtra    = classPtr->cbWndExtra;
1037     wc->hInstance     = (hInstance == user32_module) ? 0 : hInstance;
1038     wc->hIcon         = (HICON)classPtr->hIcon;
1039     wc->hIconSm       = (HICON)classPtr->hIconSm;
1040     wc->hCursor       = (HCURSOR)classPtr->hCursor;
1041     wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1042     wc->lpszMenuName  = CLASS_GetMenuNameA( classPtr );
1043     wc->lpszClassName = name;
1044     release_class_ptr( classPtr );
1045
1046     /* We must return the atom of the class here instead of just TRUE. */
1047     return atom;
1048 }
1049
1050
1051 /***********************************************************************
1052  *              GetClassInfoExW (USER32.@)
1053  */
1054 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1055 {
1056     ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1057     CLASS *classPtr;
1058
1059     TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1060
1061     if (!hInstance) hInstance = user32_module;
1062
1063     if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1064     {
1065         SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1066         return FALSE;
1067     }
1068     wc->style         = classPtr->style;
1069     wc->lpfnWndProc   = WINPROC_GetProc( classPtr->winproc, TRUE );
1070     wc->cbClsExtra    = classPtr->cbClsExtra;
1071     wc->cbWndExtra    = classPtr->cbWndExtra;
1072     wc->hInstance     = (hInstance == user32_module) ? 0 : hInstance;
1073     wc->hIcon         = (HICON)classPtr->hIcon;
1074     wc->hIconSm       = (HICON)classPtr->hIconSm;
1075     wc->hCursor       = (HCURSOR)classPtr->hCursor;
1076     wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1077     wc->lpszMenuName  = CLASS_GetMenuNameW( classPtr );
1078     wc->lpszClassName = name;
1079     release_class_ptr( classPtr );
1080
1081     /* We must return the atom of the class here instead of just TRUE. */
1082     return atom;
1083 }
1084
1085
1086 #if 0  /* toolhelp is in kernel, so this cannot work */
1087
1088 /***********************************************************************
1089  *              ClassFirst (TOOLHELP.69)
1090  */
1091 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1092 {
1093     TRACE("%p\n",pClassEntry);
1094     pClassEntry->wNext = 1;
1095     return ClassNext16( pClassEntry );
1096 }
1097
1098
1099 /***********************************************************************
1100  *              ClassNext (TOOLHELP.70)
1101  */
1102 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1103 {
1104     int i;
1105     CLASS *class = firstClass;
1106
1107     TRACE("%p\n",pClassEntry);
1108
1109     if (!pClassEntry->wNext) return FALSE;
1110     for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1111     if (!class)
1112     {
1113         pClassEntry->wNext = 0;
1114         return FALSE;
1115     }
1116     pClassEntry->hInst = class->hInstance;
1117     pClassEntry->wNext++;
1118     GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1119                           sizeof(pClassEntry->szClassName) );
1120     return TRUE;
1121 }
1122 #endif
1123
1124 /* 64bit versions */
1125
1126 #ifdef GetClassLongPtrA
1127 #undef GetClassLongPtrA
1128 #endif
1129
1130 #ifdef GetClassLongPtrW
1131 #undef GetClassLongPtrW
1132 #endif
1133
1134 #ifdef SetClassLongPtrA
1135 #undef SetClassLongPtrA
1136 #endif
1137
1138 #ifdef SetClassLongPtrW
1139 #undef SetClassLongPtrW
1140 #endif
1141
1142 /***********************************************************************
1143  *              GetClassLongPtrA (USER32.@)
1144  */
1145 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1146 {
1147     FIXME("\n");
1148     return 0;
1149 }
1150
1151 /***********************************************************************
1152  *              GetClassLongPtrW (USER32.@)
1153  */
1154 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1155 {
1156     FIXME("\n");
1157     return 0;
1158 }
1159
1160 /***********************************************************************
1161  *              SetClassLongPtrW (USER32.@)
1162  */
1163 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1164 {
1165     FIXME("\n");
1166     return 0;
1167 }
1168
1169 /***********************************************************************
1170  *              SetClassLongPtrA (USER32.@)
1171  */
1172 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1173 {
1174     FIXME("\n");
1175     return 0;
1176 }