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 = wine_server_user_handle( hwnd );
133 req->extra_offset = -1;
134 switch(offset)
135 {
136 case GCW_ATOM:
137 req->flags = SET_CLASS_ATOM;
138 req->atom = LOWORD(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 = wine_server_client_ptr( (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 (IS_INTRESOURCE(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 (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
203 if (!IS_INTRESOURCE(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 (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
223 if (!IS_INTRESOURCE(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_FindClass
259 *
260 * Return a pointer to the class.
261 * hinstance has been normalized by the caller.
262 */
263 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
264 {
265 struct list *ptr;
266 ATOM atom = get_int_atom_value( name );
267
268 USER_Lock();
269
270 LIST_FOR_EACH( ptr, &class_list )
271 {
272 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
273 if (atom)
274 {
275 if (class->atomName != atom) continue;
276 }
277 else
278 {
279 if (!name || strcmpiW( class->name, name )) continue;
280 }
281 if (!hinstance || !class->local || class->hInstance == hinstance)
282 {
283 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
284 return class;
285 }
286 }
287 USER_Unlock();
288 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
289 return NULL;
290 }
291
292
293 /***********************************************************************
294 * CLASS_RegisterClass
295 *
296 * The real RegisterClass() functionality.
297 */
298 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
299 DWORD style, INT classExtra, INT winExtra )
300 {
301 CLASS *classPtr;
302 BOOL ret;
303
304 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
305 debugstr_w(name), hInstance, style, classExtra, winExtra );
306
307 /* Fix the extra bytes value */
308
309 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
310 WARN("Class extra bytes %d is > 40\n", classExtra);
311 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
312 WARN("Win extra bytes %d is > 40\n", winExtra );
313
314 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
315 if (!classPtr) return NULL;
316
317 classPtr->atomName = get_int_atom_value( name );
318 if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
319 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
320
321 SERVER_START_REQ( create_class )
322 {
323 req->local = local;
324 req->style = style;
325 req->instance = wine_server_client_ptr( hInstance );
326 req->extra = classExtra;
327 req->win_extra = winExtra;
328 req->client_ptr = wine_server_client_ptr( classPtr );
329 req->atom = classPtr->atomName;
330 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
331 ret = !wine_server_call_err( req );
332 classPtr->atomName = reply->atom;
333 }
334 SERVER_END_REQ;
335 if (!ret)
336 {
337 HeapFree( GetProcessHeap(), 0, classPtr );
338 return NULL;
339 }
340
341 classPtr->style = style;
342 classPtr->local = local;
343 classPtr->cbWndExtra = winExtra;
344 classPtr->cbClsExtra = classExtra;
345 classPtr->hInstance = hInstance;
346
347 /* Other non-null values must be set by caller */
348
349 USER_Lock();
350 if (local) list_add_head( &class_list, &classPtr->entry );
351 else list_add_tail( &class_list, &classPtr->entry );
352 return classPtr;
353 }
354
355
356 /***********************************************************************
357 * register_builtin
358 *
359 * Register a builtin control class.
360 * This allows having both ASCII and Unicode winprocs for the same class.
361 */
362 static void register_builtin( const struct builtin_class_descr *descr )
363 {
364 CLASS *classPtr;
365
366 if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
367 descr->style, 0, descr->extra ))) return;
368
369 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
370 classPtr->hbrBackground = descr->brush;
371 classPtr->winproc = BUILTIN_WINPROC( descr->proc );
372 release_class_ptr( classPtr );
373 }
374
375
376 /***********************************************************************
377 * CLASS_RegisterBuiltinClasses
378 */
379 void CLASS_RegisterBuiltinClasses(void)
380 {
381 register_builtin( &DESKTOP_builtin_class );
382 register_builtin( &BUTTON_builtin_class );
383 register_builtin( &COMBO_builtin_class );
384 register_builtin( &COMBOLBOX_builtin_class );
385 register_builtin( &DIALOG_builtin_class );
386 register_builtin( &EDIT_builtin_class );
387 register_builtin( &ICONTITLE_builtin_class );
388 register_builtin( &LISTBOX_builtin_class );
389 register_builtin( &MDICLIENT_builtin_class );
390 register_builtin( &MENU_builtin_class );
391 register_builtin( &MESSAGE_builtin_class );
392 register_builtin( &SCROLL_builtin_class );
393 register_builtin( &STATIC_builtin_class );
394 }
395
396
397 /***********************************************************************
398 * get_class_winproc
399 */
400 WNDPROC get_class_winproc( CLASS *class )
401 {
402 return class->winproc;
403 }
404
405
406 /***********************************************************************
407 * get_class_dce
408 */
409 struct dce *get_class_dce( CLASS *class )
410 {
411 return class->dce;
412 }
413
414
415 /***********************************************************************
416 * set_class_dce
417 */
418 struct dce *set_class_dce( CLASS *class, struct dce *dce )
419 {
420 if (class->dce) return class->dce; /* already set, don't change it */
421 class->dce = dce;
422 return dce;
423 }
424
425
426 /***********************************************************************
427 * RegisterClassA (USER32.@)
428 *
429 * Register a window class.
430 *
431 * RETURNS
432 * >0: Unique identifier
433 * 0: Failure
434 */
435 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
436 {
437 WNDCLASSEXA wcex;
438
439 wcex.cbSize = sizeof(wcex);
440 wcex.style = wc->style;
441 wcex.lpfnWndProc = wc->lpfnWndProc;
442 wcex.cbClsExtra = wc->cbClsExtra;
443 wcex.cbWndExtra = wc->cbWndExtra;
444 wcex.hInstance = wc->hInstance;
445 wcex.hIcon = wc->hIcon;
446 wcex.hCursor = wc->hCursor;
447 wcex.hbrBackground = wc->hbrBackground;
448 wcex.lpszMenuName = wc->lpszMenuName;
449 wcex.lpszClassName = wc->lpszClassName;
450 wcex.hIconSm = 0;
451 return RegisterClassExA( &wcex );
452 }
453
454
455 /***********************************************************************
456 * RegisterClassW (USER32.@)
457 *
458 * See RegisterClassA.
459 */
460 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
461 {
462 WNDCLASSEXW wcex;
463
464 wcex.cbSize = sizeof(wcex);
465 wcex.style = wc->style;
466 wcex.lpfnWndProc = wc->lpfnWndProc;
467 wcex.cbClsExtra = wc->cbClsExtra;
468 wcex.cbWndExtra = wc->cbWndExtra;
469 wcex.hInstance = wc->hInstance;
470 wcex.hIcon = wc->hIcon;
471 wcex.hCursor = wc->hCursor;
472 wcex.hbrBackground = wc->hbrBackground;
473 wcex.lpszMenuName = wc->lpszMenuName;
474 wcex.lpszClassName = wc->lpszClassName;
475 wcex.hIconSm = 0;
476 return RegisterClassExW( &wcex );
477 }
478
479
480 /***********************************************************************
481 * RegisterClassExA (USER32.@)
482 */
483 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
484 {
485 ATOM atom;
486 CLASS *classPtr;
487 HINSTANCE instance;
488
489 if (wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
490 wc->hInstance == user32_module) /* we can't register a class for user32 */
491 {
492 SetLastError( ERROR_INVALID_PARAMETER );
493 return 0;
494 }
495 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
496
497 if (!IS_INTRESOURCE(wc->lpszClassName))
498 {
499 WCHAR name[MAX_ATOM_LEN + 1];
500
501 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
502 classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
503 wc->style, wc->cbClsExtra, wc->cbWndExtra );
504 }
505 else
506 {
507 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
508 !(wc->style & CS_GLOBALCLASS), wc->style,
509 wc->cbClsExtra, wc->cbWndExtra );
510 }
511 if (!classPtr) return 0;
512 atom = classPtr->atomName;
513
514 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
515 debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
516 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
517
518 classPtr->hIcon = wc->hIcon;
519 classPtr->hIconSm = wc->hIconSm;
520 classPtr->hCursor = wc->hCursor;
521 classPtr->hbrBackground = wc->hbrBackground;
522 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, FALSE );
523 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
524 release_class_ptr( classPtr );
525 return atom;
526 }
527
528
529 /***********************************************************************
530 * RegisterClassExW (USER32.@)
531 */
532 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
533 {
534 ATOM atom;
535 CLASS *classPtr;
536 HINSTANCE instance;
537
538 if (wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
539 wc->hInstance == user32_module) /* we can't register a class for user32 */
540 {
541 SetLastError( ERROR_INVALID_PARAMETER );
542 return 0;
543 }
544 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
545
546 if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
547 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
548 return 0;
549
550 atom = classPtr->atomName;
551
552 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
553 debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
554 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
555
556 classPtr->hIcon = wc->hIcon;
557 classPtr->hIconSm = wc->hIconSm;
558 classPtr->hCursor = wc->hCursor;
559 classPtr->hbrBackground = wc->hbrBackground;
560 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, TRUE );
561 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
562 release_class_ptr( classPtr );
563 return atom;
564 }
565
566
567 /***********************************************************************
568 * UnregisterClassA (USER32.@)
569 */
570 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
571 {
572 if (!IS_INTRESOURCE(className))
573 {
574 WCHAR name[MAX_ATOM_LEN + 1];
575
576 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
577 return FALSE;
578 return UnregisterClassW( name, hInstance );
579 }
580 return UnregisterClassW( (LPCWSTR)className, hInstance );
581 }
582
583 /***********************************************************************
584 * UnregisterClassW (USER32.@)
585 */
586 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
587 {
588 CLASS *classPtr = NULL;
589
590 SERVER_START_REQ( destroy_class )
591 {
592 req->instance = wine_server_client_ptr( hInstance );
593 if (!(req->atom = get_int_atom_value(className)) && className)
594 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
595 if (!wine_server_call_err( req )) classPtr = wine_server_get_ptr( reply->client_ptr );
596 }
597 SERVER_END_REQ;
598
599 if (classPtr) CLASS_FreeClass( classPtr );
600 return (classPtr != NULL);
601 }
602
603
604 /***********************************************************************
605 * GetClassWord (USER32.@)
606 */
607 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
608 {
609 CLASS *class;
610 WORD retvalue = 0;
611
612 if (offset < 0) return GetClassLongA( hwnd, offset );
613
614 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
615
616 if (class == CLASS_OTHER_PROCESS)
617 {
618 SERVER_START_REQ( set_class_info )
619 {
620 req->window = wine_server_user_handle( hwnd );
621 req->flags = 0;
622 req->extra_offset = offset;
623 req->extra_size = sizeof(retvalue);
624 if (!wine_server_call_err( req ))
625 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
626 }
627 SERVER_END_REQ;
628 return retvalue;
629 }
630
631 if (offset <= class->cbClsExtra - sizeof(WORD))
632 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
633 else
634 SetLastError( ERROR_INVALID_INDEX );
635 release_class_ptr( class );
636 return retvalue;
637 }
638
639
640 /***********************************************************************
641 * CLASS_GetClassLong
642 *
643 * Implementation of GetClassLong(Ptr)A/W
644 */
645 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
646 BOOL unicode )
647 {
648 CLASS *class;
649 ULONG_PTR retvalue = 0;
650
651 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
652
653 if (class == CLASS_OTHER_PROCESS)
654 {
655 SERVER_START_REQ( set_class_info )
656 {
657 req->window = wine_server_user_handle( hwnd );
658 req->flags = 0;
659 req->extra_offset = (offset >= 0) ? offset : -1;
660 req->extra_size = (offset >= 0) ? size : 0;
661 if (!wine_server_call_err( req ))
662 {
663 switch(offset)
664 {
665 case GCLP_HBRBACKGROUND:
666 case GCLP_HCURSOR:
667 case GCLP_HICON:
668 case GCLP_HICONSM:
669 case GCLP_WNDPROC:
670 case GCLP_MENUNAME:
671 FIXME( "offset %d (%s) not supported on other process window %p\n",
672 offset, SPY_GetClassLongOffsetName(offset), hwnd );
673 SetLastError( ERROR_INVALID_HANDLE );
674 break;
675 case GCL_STYLE:
676 retvalue = reply->old_style;
677 break;
678 case GCL_CBWNDEXTRA:
679 retvalue = reply->old_win_extra;
680 break;
681 case GCL_CBCLSEXTRA:
682 retvalue = reply->old_extra;
683 break;
684 case GCLP_HMODULE:
685 retvalue = (ULONG_PTR)wine_server_get_ptr( reply->old_instance );
686 break;
687 case GCW_ATOM:
688 retvalue = reply->old_atom;
689 break;
690 default:
691 if (offset >= 0)
692 {
693 if (size == sizeof(DWORD))
694 {
695 DWORD retdword;
696 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
697 retvalue = retdword;
698 }
699 else
700 memcpy( &retvalue, &reply->old_extra_value,
701 sizeof(ULONG_PTR) );
702 }
703 else SetLastError( ERROR_INVALID_INDEX );
704 break;
705 }
706 }
707 }
708 SERVER_END_REQ;
709 return retvalue;
710 }
711
712 if (offset >= 0)
713 {
714 if (offset <= class->cbClsExtra - size)
715 {
716 if (size == sizeof(DWORD))
717 {
718 DWORD retdword;
719 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
720 retvalue = retdword;
721 }
722 else
723 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
724 }
725 else
726 SetLastError( ERROR_INVALID_INDEX );
727 release_class_ptr( class );
728 return retvalue;
729 }
730
731 switch(offset)
732 {
733 case GCLP_HBRBACKGROUND:
734 retvalue = (ULONG_PTR)class->hbrBackground;
735 break;
736 case GCLP_HCURSOR:
737 retvalue = (ULONG_PTR)class->hCursor;
738 break;
739 case GCLP_HICON:
740 retvalue = (ULONG_PTR)class->hIcon;
741 break;
742 case GCLP_HICONSM:
743 retvalue = (ULONG_PTR)class->hIconSm;
744 break;
745 case GCL_STYLE:
746 retvalue = class->style;
747 break;
748 case GCL_CBWNDEXTRA:
749 retvalue = class->cbWndExtra;
750 break;
751 case GCL_CBCLSEXTRA:
752 retvalue = class->cbClsExtra;
753 break;
754 case GCLP_HMODULE:
755 retvalue = (ULONG_PTR)class->hInstance;
756 break;
757 case GCLP_WNDPROC:
758 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
759 break;
760 case GCLP_MENUNAME:
761 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
762 if (unicode)
763 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
764 else
765 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
766 break;
767 case GCW_ATOM:
768 retvalue = class->atomName;
769 break;
770 default:
771 SetLastError( ERROR_INVALID_INDEX );
772 break;
773 }
774 release_class_ptr( class );
775 return retvalue;
776 }
777
778
779 /***********************************************************************
780 * GetClassLongW (USER32.@)
781 */
782 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
783 {
784 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
785 }
786
787
788
789 /***********************************************************************
790 * GetClassLongA (USER32.@)
791 */
792 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
793 {
794 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
795 }
796
797
798 /***********************************************************************
799 * SetClassWord (USER32.@)
800 */
801 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
802 {
803 CLASS *class;
804 WORD retval = 0;
805
806 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
807
808 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
809
810 SERVER_START_REQ( set_class_info )
811 {
812 req->window = wine_server_user_handle( hwnd );
813 req->flags = SET_CLASS_EXTRA;
814 req->extra_offset = offset;
815 req->extra_size = sizeof(newval);
816 memcpy( &req->extra_value, &newval, sizeof(newval) );
817 if (!wine_server_call_err( req ))
818 {
819 void *ptr = (char *)(class + 1) + offset;
820 memcpy( &retval, ptr, sizeof(retval) );
821 memcpy( ptr, &newval, sizeof(newval) );
822 }
823 }
824 SERVER_END_REQ;
825 release_class_ptr( class );
826 return retval;
827 }
828
829
830 /***********************************************************************
831 * CLASS_SetClassLong
832 *
833 * Implementation of SetClassLong(Ptr)A/W
834 */
835 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
836 UINT size, BOOL unicode )
837 {
838 CLASS *class;
839 ULONG_PTR retval = 0;
840
841 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
842
843 if (offset >= 0)
844 {
845 if (set_server_info( hwnd, offset, newval, size ))
846 {
847 void *ptr = (char *)(class + 1) + offset;
848 if ( size == sizeof(LONG) )
849 {
850 DWORD retdword;
851 LONG newlong = newval;
852 memcpy( &retdword, ptr, sizeof(DWORD) );
853 memcpy( ptr, &newlong, sizeof(LONG) );
854 retval = retdword;
855 }
856 else
857 {
858 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
859 memcpy( ptr, &newval, sizeof(LONG_PTR) );
860 }
861 }
862 }
863 else switch(offset)
864 {
865 case GCLP_MENUNAME:
866 if ( unicode )
867 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
868 else
869 CLASS_SetMenuNameA( class, (LPCSTR)newval );
870 retval = 0; /* Old value is now meaningless anyway */
871 break;
872 case GCLP_WNDPROC:
873 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
874 class->winproc = WINPROC_AllocProc( (WNDPROC)newval, unicode );
875 break;
876 case GCLP_HBRBACKGROUND:
877 retval = (ULONG_PTR)class->hbrBackground;
878 class->hbrBackground = (HBRUSH)newval;
879 break;
880 case GCLP_HCURSOR:
881 retval = (ULONG_PTR)class->hCursor;
882 class->hCursor = (HCURSOR)newval;
883 break;
884 case GCLP_HICON:
885 retval = (ULONG_PTR)class->hIcon;
886 class->hIcon = (HICON)newval;
887 break;
888 case GCLP_HICONSM:
889 retval = (ULONG_PTR)class->hIconSm;
890 class->hIconSm = (HICON)newval;
891 break;
892 case GCL_STYLE:
893 if (!set_server_info( hwnd, offset, newval, size )) break;
894 retval = class->style;
895 class->style = newval;
896 break;
897 case GCL_CBWNDEXTRA:
898 if (!set_server_info( hwnd, offset, newval, size )) break;
899 retval = class->cbWndExtra;
900 class->cbWndExtra = newval;
901 break;
902 case GCLP_HMODULE:
903 if (!set_server_info( hwnd, offset, newval, size )) break;
904 retval = (ULONG_PTR)class->hInstance;
905 class->hInstance = (HINSTANCE)newval;
906 break;
907 case GCW_ATOM:
908 if (!set_server_info( hwnd, offset, newval, size )) break;
909 retval = class->atomName;
910 class->atomName = newval;
911 GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
912 break;
913 case GCL_CBCLSEXTRA: /* cannot change this one */
914 SetLastError( ERROR_INVALID_PARAMETER );
915 break;
916 default:
917 SetLastError( ERROR_INVALID_INDEX );
918 break;
919 }
920 release_class_ptr( class );
921 return retval;
922 }
923
924
925 /***********************************************************************
926 * SetClassLongW (USER32.@)
927 */
928 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
929 {
930 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
931 }
932
933
934 /***********************************************************************
935 * SetClassLongA (USER32.@)
936 */
937 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
938 {
939 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
940 }
941
942
943 /***********************************************************************
944 * GetClassNameA (USER32.@)
945 */
946 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
947 {
948 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
949 DWORD len;
950
951 if (count <= 0) return 0;
952 if (!GetClassNameW( hwnd, tmpbuf, sizeof(tmpbuf)/sizeof(WCHAR) )) return 0;
953 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
954 buffer[len] = 0;
955 return len;
956 }
957
958
959 /***********************************************************************
960 * GetClassNameW (USER32.@)
961 */
962 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
963 {
964 CLASS *class;
965 INT ret;
966
967 TRACE("%p %p %d\n", hwnd, buffer, count);
968
969 if (count <= 0) return 0;
970
971 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
972
973 if (class == CLASS_OTHER_PROCESS)
974 {
975 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
976
977 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
978 if (ret)
979 {
980 ret = min(count - 1, ret);
981 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
982 buffer[ret] = 0;
983 }
984 }
985 else
986 {
987 lstrcpynW( buffer, class->name, count );
988 release_class_ptr( class );
989 ret = strlenW( buffer );
990 }
991 return ret;
992 }
993
994
995 /***********************************************************************
996 * RealGetWindowClassA (USER32.@)
997 */
998 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
999 {
1000 return GetClassNameA( hwnd, buffer, count );
1001 }
1002
1003
1004 /***********************************************************************
1005 * RealGetWindowClassW (USER32.@)
1006 */
1007 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1008 {
1009 return GetClassNameW( hwnd, buffer, count );
1010 }
1011
1012
1013 /***********************************************************************
1014 * GetClassInfoA (USER32.@)
1015 */
1016 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1017 {
1018 WNDCLASSEXA wcex;
1019 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1020
1021 if (ret)
1022 {
1023 wc->style = wcex.style;
1024 wc->lpfnWndProc = wcex.lpfnWndProc;
1025 wc->cbClsExtra = wcex.cbClsExtra;
1026 wc->cbWndExtra = wcex.cbWndExtra;
1027 wc->hInstance = wcex.hInstance;
1028 wc->hIcon = wcex.hIcon;
1029 wc->hCursor = wcex.hCursor;
1030 wc->hbrBackground = wcex.hbrBackground;
1031 wc->lpszMenuName = wcex.lpszMenuName;
1032 wc->lpszClassName = wcex.lpszClassName;
1033 }
1034 return ret;
1035 }
1036
1037
1038 /***********************************************************************
1039 * GetClassInfoW (USER32.@)
1040 */
1041 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1042 {
1043 WNDCLASSEXW wcex;
1044 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1045
1046 if (ret)
1047 {
1048 wc->style = wcex.style;
1049 wc->lpfnWndProc = wcex.lpfnWndProc;
1050 wc->cbClsExtra = wcex.cbClsExtra;
1051 wc->cbWndExtra = wcex.cbWndExtra;
1052 wc->hInstance = wcex.hInstance;
1053 wc->hIcon = wcex.hIcon;
1054 wc->hCursor = wcex.hCursor;
1055 wc->hbrBackground = wcex.hbrBackground;
1056 wc->lpszMenuName = wcex.lpszMenuName;
1057 wc->lpszClassName = wcex.lpszClassName;
1058 }
1059 return ret;
1060 }
1061
1062
1063 /***********************************************************************
1064 * GetClassInfoExA (USER32.@)
1065 */
1066 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1067 {
1068 ATOM atom;
1069 CLASS *classPtr;
1070
1071 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1072
1073 if (!hInstance) hInstance = user32_module;
1074
1075 if (!IS_INTRESOURCE(name))
1076 {
1077 WCHAR nameW[MAX_ATOM_LEN + 1];
1078 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) ))
1079 return FALSE;
1080 classPtr = CLASS_FindClass( nameW, hInstance );
1081 }
1082 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1083
1084 if (!classPtr)
1085 {
1086 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1087 return FALSE;
1088 }
1089 wc->style = classPtr->style;
1090 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1091 wc->cbClsExtra = classPtr->cbClsExtra;
1092 wc->cbWndExtra = classPtr->cbWndExtra;
1093 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1094 wc->hIcon = classPtr->hIcon;
1095 wc->hIconSm = classPtr->hIconSm;
1096 wc->hCursor = classPtr->hCursor;
1097 wc->hbrBackground = classPtr->hbrBackground;
1098 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1099 wc->lpszClassName = name;
1100 atom = classPtr->atomName;
1101 release_class_ptr( classPtr );
1102
1103 /* We must return the atom of the class here instead of just TRUE. */
1104 return atom;
1105 }
1106
1107
1108 /***********************************************************************
1109 * GetClassInfoExW (USER32.@)
1110 */
1111 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1112 {
1113 ATOM atom;
1114 CLASS *classPtr;
1115
1116 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1117
1118 if (!hInstance) hInstance = user32_module;
1119
1120 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1121 {
1122 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1123 return FALSE;
1124 }
1125 wc->style = classPtr->style;
1126 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1127 wc->cbClsExtra = classPtr->cbClsExtra;
1128 wc->cbWndExtra = classPtr->cbWndExtra;
1129 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1130 wc->hIcon = classPtr->hIcon;
1131 wc->hIconSm = classPtr->hIconSm;
1132 wc->hCursor = classPtr->hCursor;
1133 wc->hbrBackground = classPtr->hbrBackground;
1134 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1135 wc->lpszClassName = name;
1136 atom = classPtr->atomName;
1137 release_class_ptr( classPtr );
1138
1139 /* We must return the atom of the class here instead of just TRUE. */
1140 return atom;
1141 }
1142
1143
1144 #if 0 /* toolhelp is in kernel, so this cannot work */
1145
1146 /***********************************************************************
1147 * ClassFirst (TOOLHELP.69)
1148 */
1149 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1150 {
1151 TRACE("%p\n",pClassEntry);
1152 pClassEntry->wNext = 1;
1153 return ClassNext16( pClassEntry );
1154 }
1155
1156
1157 /***********************************************************************
1158 * ClassNext (TOOLHELP.70)
1159 */
1160 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1161 {
1162 int i;
1163 CLASS *class = firstClass;
1164
1165 TRACE("%p\n",pClassEntry);
1166
1167 if (!pClassEntry->wNext) return FALSE;
1168 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1169 if (!class)
1170 {
1171 pClassEntry->wNext = 0;
1172 return FALSE;
1173 }
1174 pClassEntry->hInst = class->hInstance;
1175 pClassEntry->wNext++;
1176 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1177 sizeof(pClassEntry->szClassName) );
1178 return TRUE;
1179 }
1180 #endif
1181
1182 /* 64bit versions */
1183
1184 #ifdef GetClassLongPtrA
1185 #undef GetClassLongPtrA
1186 #endif
1187
1188 #ifdef GetClassLongPtrW
1189 #undef GetClassLongPtrW
1190 #endif
1191
1192 #ifdef SetClassLongPtrA
1193 #undef SetClassLongPtrA
1194 #endif
1195
1196 #ifdef SetClassLongPtrW
1197 #undef SetClassLongPtrW
1198 #endif
1199
1200 /***********************************************************************
1201 * GetClassLongPtrA (USER32.@)
1202 */
1203 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1204 {
1205 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1206 }
1207
1208 /***********************************************************************
1209 * GetClassLongPtrW (USER32.@)
1210 */
1211 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1212 {
1213 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1214 }
1215
1216 /***********************************************************************
1217 * SetClassLongPtrW (USER32.@)
1218 */
1219 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1220 {
1221 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1222 }
1223
1224 /***********************************************************************
1225 * SetClassLongPtrA (USER32.@)
1226 */
1227 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1228 {
1229 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );
1230 }
1231
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.