Release 960717
[wine/multimedia.git] / windows / class.c
blob80b6cc98c5a19904ef9c144a21ffac31923a2235
1 /*
2 * Window classes functions
4 * Copyright 1993, 1996 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include "class.h"
11 #include "heap.h"
12 #include "win.h"
13 #include "dce.h"
14 #include "atom.h"
15 #include "ldt.h"
16 #include "string32.h"
17 #include "toolhelp.h"
18 #include "winproc.h"
19 #include "stddebug.h"
20 #include "debug.h"
23 static CLASS *firstClass = NULL;
26 /***********************************************************************
27 * CLASS_DumpClass
29 * Dump the content of a class structure to stderr.
31 void CLASS_DumpClass( CLASS *ptr )
33 char className[80];
34 int i;
36 if (ptr->magic != CLASS_MAGIC)
38 fprintf( stderr, "%p is not a class\n", ptr );
39 return;
42 GlobalGetAtomName32A( ptr->atomName, className, sizeof(className) );
44 fprintf( stderr, "Class %p:\n", ptr );
45 fprintf( stderr,
46 "next=%p name=%04x '%s' style=%08x wndProc=%08x\n"
47 "inst=%04x hdce=%04x icon=%04x cursor=%04x bkgnd=%04x\n"
48 "clsExtra=%d winExtra=%d #windows=%d\n",
49 ptr->next, ptr->atomName, className, ptr->style,
50 (UINT32)ptr->winproc, ptr->hInstance, ptr->hdce,
51 ptr->hIcon, ptr->hCursor, ptr->hbrBackground,
52 ptr->cbClsExtra, ptr->cbWndExtra, ptr->cWindows );
53 if (ptr->cbClsExtra)
55 fprintf( stderr, "extra bytes:" );
56 for (i = 0; i < ptr->cbClsExtra; i++)
57 fprintf( stderr, " %02x", *((BYTE *)ptr->wExtra+i) );
58 fprintf( stderr, "\n" );
60 fprintf( stderr, "\n" );
64 /***********************************************************************
65 * CLASS_WalkClasses
67 * Walk the class list and print each class on stderr.
69 void CLASS_WalkClasses(void)
71 CLASS *ptr;
72 char className[80];
74 fprintf( stderr, " Class Name Style WndProc\n" );
75 for (ptr = firstClass; ptr; ptr = ptr->next)
77 GlobalGetAtomName32A( ptr->atomName, className, sizeof(className) );
78 fprintf( stderr, "%08x %-20.20s %08x %08x\n", (UINT32)ptr, className,
79 ptr->style, (UINT32)ptr->winproc );
81 fprintf( stderr, "\n" );
85 /***********************************************************************
86 * CLASS_GetMenuNameA
88 * Get the menu name as a ASCII string.
90 static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
92 if (!classPtr->menuNameA && classPtr->menuNameW)
94 /* We need to copy the Unicode string */
95 if ((classPtr->menuNameA = SEGPTR_ALLOC(
96 lstrlen32W(classPtr->menuNameW) + 1 )))
97 STRING32_UniToAnsi( classPtr->menuNameA, classPtr->menuNameW );
99 return classPtr->menuNameA;
103 /***********************************************************************
104 * CLASS_GetMenuNameW
106 * Get the menu name as a Unicode string.
108 static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
110 if (!classPtr->menuNameW && classPtr->menuNameA)
112 if (!HIWORD(classPtr->menuNameA))
113 return (LPWSTR)classPtr->menuNameA;
114 /* Now we need to copy the ASCII string */
115 if ((classPtr->menuNameW = HeapAlloc( SystemHeap, 0,
116 (strlen(classPtr->menuNameA)+1)*sizeof(WCHAR) )))
117 STRING32_AnsiToUni( classPtr->menuNameW, classPtr->menuNameA );
119 return classPtr->menuNameW;
123 /***********************************************************************
124 * CLASS_SetMenuNameA
126 * Set the menu name in a class structure by copying the string.
128 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
130 if (HIWORD(classPtr->menuNameA)) SEGPTR_FREE( classPtr->menuNameA );
131 if (classPtr->menuNameW) HeapFree( SystemHeap, 0, classPtr->menuNameW );
132 classPtr->menuNameA = SEGPTR_STRDUP( name );
133 classPtr->menuNameW = 0;
137 /***********************************************************************
138 * CLASS_SetMenuNameW
140 * Set the menu name in a class structure by copying the string.
142 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
144 if (!HIWORD(name))
146 CLASS_SetMenuNameA( classPtr, (LPCSTR)name );
147 return;
149 if (HIWORD(classPtr->menuNameA)) SEGPTR_FREE( classPtr->menuNameA );
150 if (classPtr->menuNameW) HeapFree( SystemHeap, 0, classPtr->menuNameW );
151 if ((classPtr->menuNameW = HeapAlloc( SystemHeap, 0,
152 (lstrlen32W(name)+1)*sizeof(WCHAR) )))
153 lstrcpy32W( classPtr->menuNameW, name );
154 classPtr->menuNameA = 0;
158 /***********************************************************************
159 * CLASS_FreeClass
161 * Free a class structure.
163 static BOOL CLASS_FreeClass( CLASS *classPtr )
165 CLASS **ppClass;
167 /* Check if we can remove this class */
169 if (classPtr->cWindows > 0) return FALSE;
171 /* Remove the class from the linked list */
173 for (ppClass = &firstClass; *ppClass; ppClass = &(*ppClass)->next)
174 if (*ppClass == classPtr) break;
175 if (!*ppClass)
177 fprintf(stderr, "ERROR: Class list corrupted\n" );
178 return FALSE;
180 *ppClass = classPtr->next;
182 /* Delete the class */
184 if (classPtr->hdce) DCE_FreeDCE( classPtr->hdce );
185 if (classPtr->hbrBackground) DeleteObject( classPtr->hbrBackground );
186 GlobalDeleteAtom( classPtr->atomName );
187 CLASS_SetMenuNameA( classPtr, NULL );
188 WINPROC_FreeProc( classPtr->winproc );
189 HeapFree( SystemHeap, 0, classPtr );
190 return TRUE;
194 /***********************************************************************
195 * CLASS_FreeModuleClasses
197 void CLASS_FreeModuleClasses( HMODULE16 hModule )
199 CLASS *ptr, *next;
201 for (ptr = firstClass; ptr; ptr = next)
203 next = ptr->next;
204 if (ptr->hInstance == hModule) CLASS_FreeClass( ptr );
209 /***********************************************************************
210 * CLASS_FindClassByAtom
212 * Return a pointer to the class.
214 CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE16 hinstance )
216 CLASS * class;
218 if (hinstance != 0xffff) hinstance = GetExePtr(hinstance);
220 /* First search task-specific classes */
222 for (class = firstClass; (class); class = class->next)
224 if (class->style & CS_GLOBALCLASS) continue;
225 if ((class->atomName == atom) &&
226 ((hinstance == 0xffff) ||
227 (hinstance == class->hInstance))) return class;
230 /* Then search global classes */
232 for (class = firstClass; (class); class = class->next)
234 if (!(class->style & CS_GLOBALCLASS)) continue;
235 if (class->atomName == atom) return class;
238 return 0;
242 /***********************************************************************
243 * CLASS_FindClassByName
245 * Return a pointer to the class.
247 CLASS *CLASS_FindClassByName( SEGPTR name, HINSTANCE hinstance )
249 ATOM atom;
251 if (!(atom = GlobalFindAtom16( name ))) return 0;
252 return CLASS_FindClassByAtom( atom, hinstance );
256 /***********************************************************************
257 * CLASS_RegisterClass
259 * The real RegisterClass() functionality.
261 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE32 hInstance,
262 DWORD style, INT32 classExtra,
263 INT32 winExtra, WNDPROC16 wndProc,
264 WINDOWPROCTYPE wndProcType )
266 CLASS *classPtr;
268 /* Check if a class with this name already exists */
270 classPtr = CLASS_FindClassByAtom( atom, hInstance );
271 if (classPtr)
273 /* Class can be created only if it is local and */
274 /* if the class with the same name is global. */
276 if (style & CS_GLOBALCLASS) return NULL;
277 if (!(classPtr->style & CS_GLOBALCLASS)) return NULL;
280 /* Fix the extra bytes value */
282 if (classExtra < 0) classExtra = 0;
283 else if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
284 fprintf(stderr, "Warning: class extra bytes %d is > 40\n", classExtra);
285 if (winExtra < 0) winExtra = 0;
286 else if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
287 fprintf( stderr, "Warning: win extra bytes %d is > 40\n", winExtra );
289 /* Create the class */
291 classPtr = (CLASS *)HeapAlloc( SystemHeap, 0, sizeof(CLASS) +
292 classExtra - sizeof(classPtr->wExtra) );
293 if (!classPtr) return NULL;
294 classPtr->next = firstClass;
295 classPtr->magic = CLASS_MAGIC;
296 classPtr->cWindows = 0;
297 classPtr->style = style;
298 classPtr->winproc = (HWINDOWPROC)0;
299 classPtr->cbWndExtra = winExtra;
300 classPtr->cbClsExtra = classExtra;
301 classPtr->hInstance = hInstance;
302 classPtr->atomName = atom;
303 classPtr->menuNameA = 0;
304 classPtr->menuNameW = 0;
305 classPtr->hdce = (style&CS_CLASSDC) ? DCE_AllocDCE(0, DCE_CLASS_DC): 0;
306 WINPROC_SetProc( &classPtr->winproc, wndProc, wndProcType );
308 /* Other values must be set by caller */
310 if (classExtra) memset( classPtr->wExtra, 0, classExtra );
311 firstClass = classPtr;
312 return classPtr;
316 /***********************************************************************
317 * RegisterClass16 (USER.57)
319 ATOM RegisterClass16( const WNDCLASS16 *wc )
321 ATOM atom;
322 CLASS *classPtr;
324 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
326 if (!(atom = GlobalAddAtom16( wc->lpszClassName ))) return 0;
327 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
328 wc->cbClsExtra, wc->cbWndExtra,
329 wc->lpfnWndProc, WIN_PROC_16 )))
331 GlobalDeleteAtom( atom );
332 return 0;
335 dprintf_class( stddeb, "RegisterClass16: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
336 atom, (DWORD)wc->lpfnWndProc, hInstance,
337 wc->hbrBackground, wc->style, wc->cbClsExtra,
338 wc->cbWndExtra, classPtr );
340 classPtr->hIcon = wc->hIcon;
341 classPtr->hIconSm = 0;
342 classPtr->hCursor = wc->hCursor;
343 classPtr->hbrBackground = wc->hbrBackground;
345 CLASS_SetMenuNameA( classPtr, HIWORD(wc->lpszMenuName) ?
346 PTR_SEG_TO_LIN(wc->lpszMenuName) : (LPCSTR)wc->lpszMenuName );
347 return atom;
351 /***********************************************************************
352 * RegisterClass32A (USER32.426)
354 ATOM RegisterClass32A( const WNDCLASS32A* wc )
356 ATOM atom;
357 CLASS *classPtr;
359 /* FIXME: this should not be necessary for Win32 */
360 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
362 if (!(atom = GlobalAddAtom32A( wc->lpszClassName ))) return 0;
363 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
364 wc->cbClsExtra, wc->cbWndExtra,
365 (WNDPROC16)wc->lpfnWndProc,
366 WIN_PROC_32A )))
368 GlobalDeleteAtom( atom );
369 return 0;
372 dprintf_class( stddeb, "RegisterClass32A: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
373 atom, (DWORD)wc->lpfnWndProc, hInstance,
374 wc->hbrBackground, wc->style, wc->cbClsExtra,
375 wc->cbWndExtra, classPtr );
377 classPtr->hIcon = (HICON16)wc->hIcon;
378 classPtr->hIconSm = 0;
379 classPtr->hCursor = (HCURSOR16)wc->hCursor;
380 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
381 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
382 return atom;
386 /***********************************************************************
387 * RegisterClass32W (USER32.429)
389 ATOM RegisterClass32W( const WNDCLASS32W* wc )
391 ATOM atom;
392 CLASS *classPtr;
394 /* FIXME: this should not be necessary for Win32 */
395 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
397 if (!(atom = GlobalAddAtom32W( wc->lpszClassName ))) return 0;
398 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
399 wc->cbClsExtra, wc->cbWndExtra,
400 (WNDPROC16)wc->lpfnWndProc,
401 WIN_PROC_32W )))
403 GlobalDeleteAtom( atom );
404 return 0;
407 dprintf_class( stddeb, "RegisterClass32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
408 atom, (DWORD)wc->lpfnWndProc, hInstance,
409 wc->hbrBackground, wc->style, wc->cbClsExtra,
410 wc->cbWndExtra, classPtr );
412 classPtr->hIcon = (HICON16)wc->hIcon;
413 classPtr->hIconSm = 0;
414 classPtr->hCursor = (HCURSOR16)wc->hCursor;
415 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
416 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
417 return atom;
421 /***********************************************************************
422 * RegisterClassEx16 (USER.397)
424 ATOM RegisterClassEx16( const WNDCLASSEX16 *wc )
426 ATOM atom;
427 CLASS *classPtr;
429 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
431 if (!(atom = GlobalAddAtom16( wc->lpszClassName ))) return 0;
432 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
433 wc->cbClsExtra, wc->cbWndExtra,
434 wc->lpfnWndProc, WIN_PROC_16 )))
436 GlobalDeleteAtom( atom );
437 return 0;
440 dprintf_class( stddeb, "RegisterClassEx16: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
441 atom, (DWORD)wc->lpfnWndProc, hInstance,
442 wc->hbrBackground, wc->style, wc->cbClsExtra,
443 wc->cbWndExtra, classPtr );
445 classPtr->hIcon = wc->hIcon;
446 classPtr->hIconSm = wc->hIconSm;
447 classPtr->hCursor = wc->hCursor;
448 classPtr->hbrBackground = wc->hbrBackground;
450 CLASS_SetMenuNameA( classPtr, HIWORD(wc->lpszMenuName) ?
451 PTR_SEG_TO_LIN(wc->lpszMenuName) : (LPCSTR)wc->lpszMenuName );
452 return atom;
456 /***********************************************************************
457 * RegisterClassEx32A (USER32.427)
459 ATOM RegisterClassEx32A( const WNDCLASSEX32A* wc )
461 ATOM atom;
462 CLASS *classPtr;
464 /* FIXME: this should not be necessary for Win32 */
465 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
467 if (!(atom = GlobalAddAtom32A( wc->lpszClassName ))) return 0;
468 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
469 wc->cbClsExtra, wc->cbWndExtra,
470 (WNDPROC16)wc->lpfnWndProc,
471 WIN_PROC_32A )))
473 GlobalDeleteAtom( atom );
474 return 0;
477 dprintf_class( stddeb, "RegisterClassEx32A: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
478 atom, (DWORD)wc->lpfnWndProc, hInstance,
479 wc->hbrBackground, wc->style, wc->cbClsExtra,
480 wc->cbWndExtra, classPtr );
482 classPtr->hIcon = (HICON16)wc->hIcon;
483 classPtr->hIconSm = (HICON16)wc->hIconSm;
484 classPtr->hCursor = (HCURSOR16)wc->hCursor;
485 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
486 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
487 return atom;
491 /***********************************************************************
492 * RegisterClassEx32W (USER32.428)
494 ATOM RegisterClassEx32W( const WNDCLASSEX32W* wc )
496 ATOM atom;
497 CLASS *classPtr;
499 /* FIXME: this should not be necessary for Win32 */
500 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
502 if (!(atom = GlobalAddAtom32W( wc->lpszClassName ))) return 0;
503 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
504 wc->cbClsExtra, wc->cbWndExtra,
505 (WNDPROC16)wc->lpfnWndProc,
506 WIN_PROC_32W )))
508 GlobalDeleteAtom( atom );
509 return 0;
512 dprintf_class( stddeb, "RegisterClassEx32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
513 atom, (DWORD)wc->lpfnWndProc, hInstance,
514 wc->hbrBackground, wc->style, wc->cbClsExtra,
515 wc->cbWndExtra, classPtr );
517 classPtr->hIcon = (HICON16)wc->hIcon;
518 classPtr->hIconSm = (HICON16)wc->hIconSm;
519 classPtr->hCursor = (HCURSOR16)wc->hCursor;
520 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
521 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
522 return atom;
526 /***********************************************************************
527 * UnregisterClass16 (USER.403)
529 BOOL16 UnregisterClass16( SEGPTR className, HINSTANCE16 hInstance )
531 CLASS *classPtr;
532 ATOM atom;
534 hInstance = GetExePtr( hInstance );
535 if (!(atom = GlobalFindAtom16( className ))) return FALSE;
536 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
537 (classPtr->hInstance != hInstance)) return FALSE;
538 return CLASS_FreeClass( classPtr );
542 /***********************************************************************
543 * UnregisterClass32A (USER32.562)
545 BOOL32 UnregisterClass32A( LPCSTR className, HINSTANCE32 hInstance )
547 CLASS *classPtr;
548 ATOM atom;
550 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
551 if (!(atom = GlobalFindAtom32A( className ))) return FALSE;
552 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
553 (classPtr->hInstance != hInstance)) return FALSE;
554 return CLASS_FreeClass( classPtr );
558 /***********************************************************************
559 * UnregisterClass32W (USER32.563)
561 BOOL32 UnregisterClass32W( LPCWSTR className, HINSTANCE32 hInstance )
563 CLASS *classPtr;
564 ATOM atom;
566 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
567 if (!(atom = GlobalFindAtom32W( className ))) return FALSE;
568 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
569 (classPtr->hInstance != hInstance)) return FALSE;
570 return CLASS_FreeClass( classPtr );
574 /***********************************************************************
575 * GetClassWord (USER.129) (USER32.218)
577 WORD GetClassWord( HWND32 hwnd, INT32 offset )
579 WND * wndPtr;
581 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
582 if (offset >= 0)
584 if (offset <= wndPtr->class->cbClsExtra - sizeof(WORD))
585 return GET_WORD(((char *)wndPtr->class->wExtra) + offset);
587 else switch(offset)
589 case GCW_HBRBACKGROUND: return wndPtr->class->hbrBackground;
590 case GCW_HCURSOR: return wndPtr->class->hCursor;
591 case GCW_HICON: return wndPtr->class->hIcon;
592 case GCW_HICONSM: return wndPtr->class->hIconSm;
593 case GCW_ATOM: return wndPtr->class->atomName;
594 case GCW_STYLE:
595 case GCW_CBWNDEXTRA:
596 case GCW_CBCLSEXTRA:
597 case GCW_HMODULE:
598 return (WORD)GetClassLong32A( hwnd, offset );
600 fprintf(stderr, "Warning: invalid offset %d for GetClassWord()\n", offset);
601 return 0;
605 /***********************************************************************
606 * GetClassLong16 (USER.131)
608 LONG GetClassLong16( HWND16 hwnd, INT16 offset )
610 WND *wndPtr;
611 LONG ret;
613 switch( offset )
615 case GCL_WNDPROC:
616 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
617 return (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_16 );
618 case GCL_MENUNAME:
619 ret = GetClassLong32A( hwnd, offset );
620 return (LONG)SEGPTR_GET( (void *)ret );
621 default:
622 return GetClassLong32A( hwnd, offset );
627 /***********************************************************************
628 * GetClassLong32A (USER32.214)
630 LONG GetClassLong32A( HWND32 hwnd, INT32 offset )
632 WND * wndPtr;
634 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
635 if (offset >= 0)
637 if (offset <= wndPtr->class->cbClsExtra - sizeof(LONG))
638 return GET_DWORD(((char *)wndPtr->class->wExtra) + offset);
640 switch(offset)
642 case GCL_STYLE: return (LONG)wndPtr->class->style;
643 case GCL_CBWNDEXTRA: return (LONG)wndPtr->class->cbWndExtra;
644 case GCL_CBCLSEXTRA: return (LONG)wndPtr->class->cbClsExtra;
645 case GCL_HMODULE: return (LONG)wndPtr->class->hInstance;
646 case GCL_WNDPROC:
647 return (LONG)WINPROC_GetProc(wndPtr->class->winproc, WIN_PROC_32A);
648 case GCL_MENUNAME:
649 return (LONG)CLASS_GetMenuNameA( wndPtr->class );
650 case GCL_HBRBACKGROUND:
651 case GCL_HCURSOR:
652 case GCL_HICON:
653 case GCL_HICONSM:
654 return GetClassWord( hwnd, offset );
656 fprintf(stderr, "Warning: invalid offset %d for GetClassLong()\n", offset);
657 return 0;
661 /***********************************************************************
662 * GetClassLong32W (USER32.215)
664 LONG GetClassLong32W( HWND32 hwnd, INT32 offset )
666 WND * wndPtr;
668 switch(offset)
670 case GCL_WNDPROC:
671 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
672 return (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_32W );
673 case GCL_MENUNAME:
674 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
675 return (LONG)CLASS_GetMenuNameW( wndPtr->class );
676 default:
677 return GetClassLong32A( hwnd, offset );
682 /***********************************************************************
683 * SetClassWord (USER.130) (USER32.468)
685 WORD SetClassWord( HWND32 hwnd, INT32 offset, WORD newval )
687 WND * wndPtr;
688 WORD retval = 0;
689 void *ptr;
691 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
692 if (offset >= 0)
694 if (offset + sizeof(WORD) <= wndPtr->class->cbClsExtra)
695 ptr = ((char *)wndPtr->class->wExtra) + offset;
696 else
698 fprintf( stderr, "Warning: invalid offset %d for SetClassWord()\n",
699 offset );
700 return 0;
703 else switch(offset)
705 case GCW_STYLE:
706 case GCW_CBWNDEXTRA:
707 case GCW_CBCLSEXTRA:
708 case GCW_HMODULE:
709 return (WORD)SetClassLong32A( hwnd, offset, (LONG)newval );
710 case GCW_HBRBACKGROUND: ptr = &wndPtr->class->hbrBackground; break;
711 case GCW_HCURSOR: ptr = &wndPtr->class->hCursor; break;
712 case GCW_HICON: ptr = &wndPtr->class->hIcon; break;
713 case GCW_HICONSM: ptr = &wndPtr->class->hIconSm; break;
714 case GCW_ATOM: ptr = &wndPtr->class->atomName; break;
715 default:
716 fprintf( stderr, "Warning: invalid offset %d for SetClassWord()\n",
717 offset);
718 return 0;
720 retval = GET_WORD(ptr);
721 PUT_WORD( ptr, newval );
722 return retval;
726 /***********************************************************************
727 * SetClassLong16 (USER.132)
729 LONG SetClassLong16( HWND16 hwnd, INT16 offset, LONG newval )
731 WND *wndPtr;
732 LONG retval;
734 switch(offset)
736 case GCL_WNDPROC:
737 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
738 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_16 );
739 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
740 WIN_PROC_16 );
741 return retval;
742 case GCL_MENUNAME:
743 return SetClassLong32A( hwnd, offset, (LONG)PTR_SEG_TO_LIN(newval) );
744 default:
745 return SetClassLong32A( hwnd, offset, newval );
750 /***********************************************************************
751 * SetClassLong32A (USER32.466)
753 LONG SetClassLong32A( HWND32 hwnd, INT32 offset, LONG newval )
755 WND * wndPtr;
756 LONG retval = 0;
757 void *ptr;
759 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
760 if (offset >= 0)
762 if (offset + sizeof(LONG) <= wndPtr->class->cbClsExtra)
763 ptr = ((char *)wndPtr->class->wExtra) + offset;
764 else
766 fprintf( stderr, "Warning: invalid offset %d for SetClassLong()\n",
767 offset );
768 return 0;
771 else switch(offset)
773 case GCL_MENUNAME:
774 CLASS_SetMenuNameA( wndPtr->class, (LPCSTR)newval );
775 return 0; /* Old value is now meaningless anyway */
776 case GCL_WNDPROC:
777 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc,
778 WIN_PROC_32A );
779 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
780 WIN_PROC_32A );
781 return retval;
782 case GCL_HBRBACKGROUND:
783 case GCL_HCURSOR:
784 case GCL_HICON:
785 case GCL_HICONSM:
786 return SetClassWord( hwnd, offset, (WORD)newval );
787 case GCL_STYLE: ptr = &wndPtr->class->style; break;
788 case GCL_CBWNDEXTRA: ptr = &wndPtr->class->cbWndExtra; break;
789 case GCL_CBCLSEXTRA: ptr = &wndPtr->class->cbClsExtra; break;
790 case GCL_HMODULE: ptr = &wndPtr->class->hInstance; break;
791 default:
792 fprintf( stderr, "Warning: invalid offset %d for SetClassLong()\n",
793 offset);
794 return 0;
796 retval = GET_DWORD(ptr);
797 PUT_DWORD( ptr, newval );
798 return retval;
802 /***********************************************************************
803 * SetClassLong32W (USER32.467)
805 LONG SetClassLong32W( HWND32 hwnd, INT32 offset, LONG newval )
807 WND *wndPtr;
808 LONG retval;
810 switch(offset)
812 case GCL_WNDPROC:
813 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
814 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_32W );
815 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
816 WIN_PROC_32W );
817 return retval;
818 case GCL_MENUNAME:
819 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
820 CLASS_SetMenuNameW( wndPtr->class, (LPCWSTR)newval );
821 return 0; /* Old value is now meaningless anyway */
822 default:
823 return SetClassLong32A( hwnd, offset, newval );
828 /***********************************************************************
829 * GetClassName16 (USER.58)
831 INT16 GetClassName16( HWND16 hwnd, LPSTR buffer, INT16 count )
833 WND *wndPtr;
834 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
835 return GlobalGetAtomName16( wndPtr->class->atomName, buffer, count );
839 /***********************************************************************
840 * GetClassName32A (USER32.216)
842 INT32 GetClassName32A( HWND32 hwnd, LPSTR buffer, INT32 count )
844 WND *wndPtr;
845 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
846 return GlobalGetAtomName32A( wndPtr->class->atomName, buffer, count );
850 /***********************************************************************
851 * GetClassName32W (USER32.217)
853 INT32 GetClassName32W( HWND32 hwnd, LPWSTR buffer, INT32 count )
855 WND *wndPtr;
856 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
857 return GlobalGetAtomName32W( wndPtr->class->atomName, buffer, count );
861 /***********************************************************************
862 * GetClassInfo16 (USER.404)
864 BOOL16 GetClassInfo16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASS16 *wc )
866 ATOM atom;
867 CLASS *classPtr;
869 hInstance = GetExePtr( hInstance );
870 if (!(atom = GlobalFindAtom16( name )) ||
871 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
872 (hInstance != classPtr->hInstance)) return FALSE;
873 wc->style = (UINT16)classPtr->style;
874 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, WIN_PROC_16 );
875 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
876 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
877 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
878 wc->hIcon = classPtr->hIcon;
879 wc->hCursor = classPtr->hCursor;
880 wc->hbrBackground = classPtr->hbrBackground;
881 wc->lpszClassName = (SEGPTR)0;
882 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
883 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
884 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
885 return TRUE;
889 /***********************************************************************
890 * GetClassInfo32A (USER32.210)
892 BOOL32 GetClassInfo32A( HINSTANCE32 hInstance, LPCSTR name, WNDCLASS32A *wc )
894 ATOM atom;
895 CLASS *classPtr;
897 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
898 if (!(atom = GlobalFindAtom32A( name )) ||
899 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
900 (hInstance != classPtr->hInstance)) return FALSE;
901 wc->style = classPtr->style;
902 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
903 WIN_PROC_32A );
904 wc->cbClsExtra = classPtr->cbClsExtra;
905 wc->cbWndExtra = classPtr->cbWndExtra;
906 wc->hInstance = classPtr->hInstance;
907 wc->hIcon = (HICON32)classPtr->hIcon;
908 wc->hCursor = (HCURSOR32)classPtr->hCursor;
909 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
910 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
911 wc->lpszClassName = NULL;
912 return TRUE;
916 /***********************************************************************
917 * GetClassInfo32W (USER32.213)
919 BOOL32 GetClassInfo32W( HINSTANCE32 hInstance, LPCWSTR name, WNDCLASS32W *wc )
921 ATOM atom;
922 CLASS *classPtr;
924 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
925 if (!(atom = GlobalFindAtom32W( name )) ||
926 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
927 (hInstance != classPtr->hInstance)) return FALSE;
928 wc->style = classPtr->style;
929 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
930 WIN_PROC_32W );
931 wc->cbClsExtra = classPtr->cbClsExtra;
932 wc->cbWndExtra = classPtr->cbWndExtra;
933 wc->hInstance = classPtr->hInstance;
934 wc->hIcon = (HICON32)classPtr->hIcon;
935 wc->hCursor = (HCURSOR32)classPtr->hCursor;
936 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
937 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
938 wc->lpszClassName = NULL;
939 return TRUE;
943 /***********************************************************************
944 * GetClassInfoEx16 (USER.398)
946 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
947 * same in Win16 as in Win32. --AJ
949 BOOL16 GetClassInfoEx16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASSEX16 *wc )
951 ATOM atom;
952 CLASS *classPtr;
954 hInstance = GetExePtr( hInstance );
955 if (!(atom = GlobalFindAtom16( name )) ||
956 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
957 (hInstance != classPtr->hInstance)) return FALSE;
958 wc->style = classPtr->style;
959 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, WIN_PROC_16 );
960 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
961 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
962 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
963 wc->hIcon = classPtr->hIcon;
964 wc->hIconSm = classPtr->hIconSm;
965 wc->hCursor = classPtr->hCursor;
966 wc->hbrBackground = classPtr->hbrBackground;
967 wc->lpszClassName = (SEGPTR)0;
968 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
969 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
970 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
971 return TRUE;
975 /***********************************************************************
976 * GetClassInfoEx32A (USER32.211)
978 BOOL32 GetClassInfoEx32A( HINSTANCE32 hInstance, LPCSTR name,
979 WNDCLASSEX32A *wc )
981 ATOM atom;
982 CLASS *classPtr;
984 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
985 if (!(atom = GlobalFindAtom32A( name )) ||
986 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
987 (hInstance != classPtr->hInstance)) return FALSE;
988 wc->style = classPtr->style;
989 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
990 WIN_PROC_32A );
991 wc->cbClsExtra = classPtr->cbClsExtra;
992 wc->cbWndExtra = classPtr->cbWndExtra;
993 wc->hInstance = classPtr->hInstance;
994 wc->hIcon = (HICON32)classPtr->hIcon;
995 wc->hIconSm = (HICON32)classPtr->hIconSm;
996 wc->hCursor = (HCURSOR32)classPtr->hCursor;
997 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
998 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
999 wc->lpszClassName = NULL;
1000 return TRUE;
1004 /***********************************************************************
1005 * GetClassInfoEx32W (USER32.212)
1007 BOOL32 GetClassInfoEx32W( HINSTANCE32 hInstance, LPCWSTR name,
1008 WNDCLASSEX32W *wc )
1010 ATOM atom;
1011 CLASS *classPtr;
1013 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
1014 if (!(atom = GlobalFindAtom32W( name )) ||
1015 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1016 (hInstance != classPtr->hInstance)) return FALSE;
1017 wc->style = classPtr->style;
1018 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
1019 WIN_PROC_32W );
1020 wc->cbClsExtra = classPtr->cbClsExtra;
1021 wc->cbWndExtra = classPtr->cbWndExtra;
1022 wc->hInstance = classPtr->hInstance;
1023 wc->hIcon = (HICON32)classPtr->hIcon;
1024 wc->hIconSm = (HICON32)classPtr->hIconSm;
1025 wc->hCursor = (HCURSOR32)classPtr->hCursor;
1026 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
1027 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1028 wc->lpszClassName = NULL;
1029 return TRUE;
1033 /***********************************************************************
1034 * ClassFirst (TOOLHELP.69)
1036 BOOL16 ClassFirst( CLASSENTRY *pClassEntry )
1038 pClassEntry->wNext = 1;
1039 return ClassNext( pClassEntry );
1043 /***********************************************************************
1044 * ClassNext (TOOLHELP.70)
1046 BOOL16 ClassNext( CLASSENTRY *pClassEntry )
1048 int i;
1049 CLASS *class = firstClass;
1051 if (!pClassEntry->wNext) return FALSE;
1052 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1053 if (!class)
1055 pClassEntry->wNext = 0;
1056 return FALSE;
1058 pClassEntry->hInst = class->hInstance;
1059 pClassEntry->wNext++;
1060 GlobalGetAtomName32A( class->atomName, pClassEntry->szClassName,
1061 sizeof(pClassEntry->szClassName) );
1062 return TRUE;