Release 961013
[wine/multimedia.git] / windows / class.c
blobc89e96f90b89bc635e96a63b76435fce979a59a9
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 dce=%08x 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, (UINT32)ptr->dce,
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->dce) DCE_FreeDCE( classPtr->dce );
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_RegisterClass
245 * The real RegisterClass() functionality.
247 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE32 hInstance,
248 DWORD style, INT32 classExtra,
249 INT32 winExtra, WNDPROC16 wndProc,
250 WINDOWPROCTYPE wndProcType )
252 CLASS *classPtr;
254 /* Check if a class with this name already exists */
256 classPtr = CLASS_FindClassByAtom( atom, hInstance );
257 if (classPtr)
259 /* Class can be created only if it is local and */
260 /* if the class with the same name is global. */
262 if (style & CS_GLOBALCLASS) return NULL;
263 if (!(classPtr->style & CS_GLOBALCLASS)) return NULL;
266 /* Fix the extra bytes value */
268 if (classExtra < 0) classExtra = 0;
269 else if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
270 fprintf(stderr, "Warning: class extra bytes %d is > 40\n", classExtra);
271 if (winExtra < 0) winExtra = 0;
272 else if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
273 fprintf( stderr, "Warning: win extra bytes %d is > 40\n", winExtra );
275 /* Create the class */
277 classPtr = (CLASS *)HeapAlloc( SystemHeap, 0, sizeof(CLASS) +
278 classExtra - sizeof(classPtr->wExtra) );
279 if (!classPtr) return NULL;
280 classPtr->next = firstClass;
281 classPtr->magic = CLASS_MAGIC;
282 classPtr->cWindows = 0;
283 classPtr->style = style;
284 classPtr->winproc = (HWINDOWPROC)0;
285 classPtr->cbWndExtra = winExtra;
286 classPtr->cbClsExtra = classExtra;
287 classPtr->hInstance = hInstance;
288 classPtr->atomName = atom;
289 classPtr->menuNameA = 0;
290 classPtr->menuNameW = 0;
291 classPtr->dce = (style & CS_CLASSDC) ?
292 DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
294 WINPROC_SetProc( &classPtr->winproc, wndProc, wndProcType );
296 /* Other values must be set by caller */
298 if (classExtra) memset( classPtr->wExtra, 0, classExtra );
299 firstClass = classPtr;
300 return classPtr;
304 /***********************************************************************
305 * RegisterClass16 (USER.57)
307 ATOM RegisterClass16( const WNDCLASS16 *wc )
309 ATOM atom;
310 CLASS *classPtr;
312 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
314 if (!(atom = GlobalAddAtom16( wc->lpszClassName ))) return 0;
315 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
316 wc->cbClsExtra, wc->cbWndExtra,
317 wc->lpfnWndProc, WIN_PROC_16 )))
319 GlobalDeleteAtom( atom );
320 return 0;
323 dprintf_class( stddeb, "RegisterClass16: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
324 atom, (DWORD)wc->lpfnWndProc, hInstance,
325 wc->hbrBackground, wc->style, wc->cbClsExtra,
326 wc->cbWndExtra, classPtr );
328 classPtr->hIcon = wc->hIcon;
329 classPtr->hIconSm = 0;
330 classPtr->hCursor = wc->hCursor;
331 classPtr->hbrBackground = wc->hbrBackground;
333 CLASS_SetMenuNameA( classPtr, HIWORD(wc->lpszMenuName) ?
334 PTR_SEG_TO_LIN(wc->lpszMenuName) : (LPCSTR)wc->lpszMenuName );
335 return atom;
339 /***********************************************************************
340 * RegisterClass32A (USER32.426)
342 ATOM RegisterClass32A( const WNDCLASS32A* wc )
344 ATOM atom;
345 CLASS *classPtr;
347 /* FIXME: this should not be necessary for Win32 */
348 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
350 if (!(atom = GlobalAddAtom32A( wc->lpszClassName ))) return 0;
351 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
352 wc->cbClsExtra, wc->cbWndExtra,
353 (WNDPROC16)wc->lpfnWndProc,
354 WIN_PROC_32A )))
356 GlobalDeleteAtom( atom );
357 return 0;
360 dprintf_class( stddeb, "RegisterClass32A: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
361 atom, (DWORD)wc->lpfnWndProc, hInstance,
362 wc->hbrBackground, wc->style, wc->cbClsExtra,
363 wc->cbWndExtra, classPtr );
365 classPtr->hIcon = (HICON16)wc->hIcon;
366 classPtr->hIconSm = 0;
367 classPtr->hCursor = (HCURSOR16)wc->hCursor;
368 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
369 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
370 return atom;
374 /***********************************************************************
375 * RegisterClass32W (USER32.429)
377 ATOM RegisterClass32W( const WNDCLASS32W* wc )
379 ATOM atom;
380 CLASS *classPtr;
382 /* FIXME: this should not be necessary for Win32 */
383 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
385 if (!(atom = GlobalAddAtom32W( wc->lpszClassName ))) return 0;
386 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
387 wc->cbClsExtra, wc->cbWndExtra,
388 (WNDPROC16)wc->lpfnWndProc,
389 WIN_PROC_32W )))
391 GlobalDeleteAtom( atom );
392 return 0;
395 dprintf_class( stddeb, "RegisterClass32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
396 atom, (DWORD)wc->lpfnWndProc, hInstance,
397 wc->hbrBackground, wc->style, wc->cbClsExtra,
398 wc->cbWndExtra, classPtr );
400 classPtr->hIcon = (HICON16)wc->hIcon;
401 classPtr->hIconSm = 0;
402 classPtr->hCursor = (HCURSOR16)wc->hCursor;
403 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
404 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
405 return atom;
409 /***********************************************************************
410 * RegisterClassEx16 (USER.397)
412 ATOM RegisterClassEx16( const WNDCLASSEX16 *wc )
414 ATOM atom;
415 CLASS *classPtr;
417 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
419 if (!(atom = GlobalAddAtom16( wc->lpszClassName ))) return 0;
420 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
421 wc->cbClsExtra, wc->cbWndExtra,
422 wc->lpfnWndProc, WIN_PROC_16 )))
424 GlobalDeleteAtom( atom );
425 return 0;
428 dprintf_class( stddeb, "RegisterClassEx16: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
429 atom, (DWORD)wc->lpfnWndProc, hInstance,
430 wc->hbrBackground, wc->style, wc->cbClsExtra,
431 wc->cbWndExtra, classPtr );
433 classPtr->hIcon = wc->hIcon;
434 classPtr->hIconSm = wc->hIconSm;
435 classPtr->hCursor = wc->hCursor;
436 classPtr->hbrBackground = wc->hbrBackground;
438 CLASS_SetMenuNameA( classPtr, HIWORD(wc->lpszMenuName) ?
439 PTR_SEG_TO_LIN(wc->lpszMenuName) : (LPCSTR)wc->lpszMenuName );
440 return atom;
444 /***********************************************************************
445 * RegisterClassEx32A (USER32.427)
447 ATOM RegisterClassEx32A( const WNDCLASSEX32A* wc )
449 ATOM atom;
450 CLASS *classPtr;
452 /* FIXME: this should not be necessary for Win32 */
453 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
455 if (!(atom = GlobalAddAtom32A( wc->lpszClassName ))) return 0;
456 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
457 wc->cbClsExtra, wc->cbWndExtra,
458 (WNDPROC16)wc->lpfnWndProc,
459 WIN_PROC_32A )))
461 GlobalDeleteAtom( atom );
462 return 0;
465 dprintf_class( stddeb, "RegisterClassEx32A: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
466 atom, (DWORD)wc->lpfnWndProc, hInstance,
467 wc->hbrBackground, wc->style, wc->cbClsExtra,
468 wc->cbWndExtra, classPtr );
470 classPtr->hIcon = (HICON16)wc->hIcon;
471 classPtr->hIconSm = (HICON16)wc->hIconSm;
472 classPtr->hCursor = (HCURSOR16)wc->hCursor;
473 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
474 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
475 return atom;
479 /***********************************************************************
480 * RegisterClassEx32W (USER32.428)
482 ATOM RegisterClassEx32W( const WNDCLASSEX32W* wc )
484 ATOM atom;
485 CLASS *classPtr;
487 /* FIXME: this should not be necessary for Win32 */
488 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
490 if (!(atom = GlobalAddAtom32W( wc->lpszClassName ))) return 0;
491 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
492 wc->cbClsExtra, wc->cbWndExtra,
493 (WNDPROC16)wc->lpfnWndProc,
494 WIN_PROC_32W )))
496 GlobalDeleteAtom( atom );
497 return 0;
500 dprintf_class( stddeb, "RegisterClassEx32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
501 atom, (DWORD)wc->lpfnWndProc, hInstance,
502 wc->hbrBackground, wc->style, wc->cbClsExtra,
503 wc->cbWndExtra, classPtr );
505 classPtr->hIcon = (HICON16)wc->hIcon;
506 classPtr->hIconSm = (HICON16)wc->hIconSm;
507 classPtr->hCursor = (HCURSOR16)wc->hCursor;
508 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
509 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
510 return atom;
514 /***********************************************************************
515 * UnregisterClass16 (USER.403)
517 BOOL16 UnregisterClass16( SEGPTR className, HINSTANCE16 hInstance )
519 CLASS *classPtr;
520 ATOM atom;
522 hInstance = GetExePtr( hInstance );
523 if (!(atom = GlobalFindAtom16( className ))) return FALSE;
524 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
525 (classPtr->hInstance != hInstance)) return FALSE;
526 return CLASS_FreeClass( classPtr );
530 /***********************************************************************
531 * UnregisterClass32A (USER32.562)
533 BOOL32 UnregisterClass32A( LPCSTR className, HINSTANCE32 hInstance )
535 CLASS *classPtr;
536 ATOM atom;
538 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
539 if (!(atom = GlobalFindAtom32A( className ))) return FALSE;
540 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
541 (classPtr->hInstance != hInstance)) return FALSE;
542 return CLASS_FreeClass( classPtr );
546 /***********************************************************************
547 * UnregisterClass32W (USER32.563)
549 BOOL32 UnregisterClass32W( LPCWSTR className, HINSTANCE32 hInstance )
551 CLASS *classPtr;
552 ATOM atom;
554 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
555 if (!(atom = GlobalFindAtom32W( className ))) return FALSE;
556 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
557 (classPtr->hInstance != hInstance)) return FALSE;
558 return CLASS_FreeClass( classPtr );
562 /***********************************************************************
563 * GetClassWord (USER.129) (USER32.218)
565 WORD GetClassWord( HWND32 hwnd, INT32 offset )
567 WND * wndPtr;
569 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
570 if (offset >= 0)
572 if (offset <= wndPtr->class->cbClsExtra - sizeof(WORD))
573 return GET_WORD(((char *)wndPtr->class->wExtra) + offset);
575 else switch(offset)
577 case GCW_HBRBACKGROUND: return wndPtr->class->hbrBackground;
578 case GCW_HCURSOR: return wndPtr->class->hCursor;
579 case GCW_HICON: return wndPtr->class->hIcon;
580 case GCW_HICONSM: return wndPtr->class->hIconSm;
581 case GCW_ATOM: return wndPtr->class->atomName;
582 case GCW_STYLE:
583 case GCW_CBWNDEXTRA:
584 case GCW_CBCLSEXTRA:
585 case GCW_HMODULE:
586 return (WORD)GetClassLong32A( hwnd, offset );
588 fprintf(stderr, "Warning: invalid offset %d for GetClassWord()\n", offset);
589 return 0;
593 /***********************************************************************
594 * GetClassLong16 (USER.131)
596 LONG GetClassLong16( HWND16 hwnd, INT16 offset )
598 WND *wndPtr;
599 LONG ret;
601 switch( offset )
603 case GCL_WNDPROC:
604 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
605 return (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_16 );
606 case GCL_MENUNAME:
607 ret = GetClassLong32A( hwnd, offset );
608 return (LONG)SEGPTR_GET( (void *)ret );
609 default:
610 return GetClassLong32A( hwnd, offset );
615 /***********************************************************************
616 * GetClassLong32A (USER32.214)
618 LONG GetClassLong32A( HWND32 hwnd, INT32 offset )
620 WND * wndPtr;
622 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
623 if (offset >= 0)
625 if (offset <= wndPtr->class->cbClsExtra - sizeof(LONG))
626 return GET_DWORD(((char *)wndPtr->class->wExtra) + offset);
628 switch(offset)
630 case GCL_STYLE: return (LONG)wndPtr->class->style;
631 case GCL_CBWNDEXTRA: return (LONG)wndPtr->class->cbWndExtra;
632 case GCL_CBCLSEXTRA: return (LONG)wndPtr->class->cbClsExtra;
633 case GCL_HMODULE: return (LONG)wndPtr->class->hInstance;
634 case GCL_WNDPROC:
635 return (LONG)WINPROC_GetProc(wndPtr->class->winproc, WIN_PROC_32A);
636 case GCL_MENUNAME:
637 return (LONG)CLASS_GetMenuNameA( wndPtr->class );
638 case GCL_HBRBACKGROUND:
639 case GCL_HCURSOR:
640 case GCL_HICON:
641 case GCL_HICONSM:
642 return GetClassWord( hwnd, offset );
644 fprintf(stderr, "Warning: invalid offset %d for GetClassLong()\n", offset);
645 return 0;
649 /***********************************************************************
650 * GetClassLong32W (USER32.215)
652 LONG GetClassLong32W( HWND32 hwnd, INT32 offset )
654 WND * wndPtr;
656 switch(offset)
658 case GCL_WNDPROC:
659 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
660 return (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_32W );
661 case GCL_MENUNAME:
662 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
663 return (LONG)CLASS_GetMenuNameW( wndPtr->class );
664 default:
665 return GetClassLong32A( hwnd, offset );
670 /***********************************************************************
671 * SetClassWord (USER.130) (USER32.468)
673 WORD SetClassWord( HWND32 hwnd, INT32 offset, WORD newval )
675 WND * wndPtr;
676 WORD retval = 0;
677 void *ptr;
679 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
680 if (offset >= 0)
682 if (offset + sizeof(WORD) <= wndPtr->class->cbClsExtra)
683 ptr = ((char *)wndPtr->class->wExtra) + offset;
684 else
686 fprintf( stderr, "Warning: invalid offset %d for SetClassWord()\n",
687 offset );
688 return 0;
691 else switch(offset)
693 case GCW_STYLE:
694 case GCW_CBWNDEXTRA:
695 case GCW_CBCLSEXTRA:
696 case GCW_HMODULE:
697 return (WORD)SetClassLong32A( hwnd, offset, (LONG)newval );
698 case GCW_HBRBACKGROUND: ptr = &wndPtr->class->hbrBackground; break;
699 case GCW_HCURSOR: ptr = &wndPtr->class->hCursor; break;
700 case GCW_HICON: ptr = &wndPtr->class->hIcon; break;
701 case GCW_HICONSM: ptr = &wndPtr->class->hIconSm; break;
702 case GCW_ATOM: ptr = &wndPtr->class->atomName; break;
703 default:
704 fprintf( stderr, "Warning: invalid offset %d for SetClassWord()\n",
705 offset);
706 return 0;
708 retval = GET_WORD(ptr);
709 PUT_WORD( ptr, newval );
710 return retval;
714 /***********************************************************************
715 * SetClassLong16 (USER.132)
717 LONG SetClassLong16( HWND16 hwnd, INT16 offset, LONG newval )
719 WND *wndPtr;
720 LONG retval;
722 switch(offset)
724 case GCL_WNDPROC:
725 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
726 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_16 );
727 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
728 WIN_PROC_16 );
729 return retval;
730 case GCL_MENUNAME:
731 return SetClassLong32A( hwnd, offset, (LONG)PTR_SEG_TO_LIN(newval) );
732 default:
733 return SetClassLong32A( hwnd, offset, newval );
738 /***********************************************************************
739 * SetClassLong32A (USER32.466)
741 LONG SetClassLong32A( HWND32 hwnd, INT32 offset, LONG newval )
743 WND * wndPtr;
744 LONG retval = 0;
745 void *ptr;
747 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
748 if (offset >= 0)
750 if (offset + sizeof(LONG) <= wndPtr->class->cbClsExtra)
751 ptr = ((char *)wndPtr->class->wExtra) + offset;
752 else
754 fprintf( stderr, "Warning: invalid offset %d for SetClassLong()\n",
755 offset );
756 return 0;
759 else switch(offset)
761 case GCL_MENUNAME:
762 CLASS_SetMenuNameA( wndPtr->class, (LPCSTR)newval );
763 return 0; /* Old value is now meaningless anyway */
764 case GCL_WNDPROC:
765 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc,
766 WIN_PROC_32A );
767 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
768 WIN_PROC_32A );
769 return retval;
770 case GCL_HBRBACKGROUND:
771 case GCL_HCURSOR:
772 case GCL_HICON:
773 case GCL_HICONSM:
774 return SetClassWord( hwnd, offset, (WORD)newval );
775 case GCL_STYLE: ptr = &wndPtr->class->style; break;
776 case GCL_CBWNDEXTRA: ptr = &wndPtr->class->cbWndExtra; break;
777 case GCL_CBCLSEXTRA: ptr = &wndPtr->class->cbClsExtra; break;
778 case GCL_HMODULE: ptr = &wndPtr->class->hInstance; break;
779 default:
780 fprintf( stderr, "Warning: invalid offset %d for SetClassLong()\n",
781 offset);
782 return 0;
784 retval = GET_DWORD(ptr);
785 PUT_DWORD( ptr, newval );
786 return retval;
790 /***********************************************************************
791 * SetClassLong32W (USER32.467)
793 LONG SetClassLong32W( HWND32 hwnd, INT32 offset, LONG newval )
795 WND *wndPtr;
796 LONG retval;
798 switch(offset)
800 case GCL_WNDPROC:
801 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
802 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_32W );
803 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
804 WIN_PROC_32W );
805 return retval;
806 case GCL_MENUNAME:
807 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
808 CLASS_SetMenuNameW( wndPtr->class, (LPCWSTR)newval );
809 return 0; /* Old value is now meaningless anyway */
810 default:
811 return SetClassLong32A( hwnd, offset, newval );
816 /***********************************************************************
817 * GetClassName16 (USER.58)
819 INT16 GetClassName16( HWND16 hwnd, LPSTR buffer, INT16 count )
821 WND *wndPtr;
822 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
823 return GlobalGetAtomName16( wndPtr->class->atomName, buffer, count );
827 /***********************************************************************
828 * GetClassName32A (USER32.216)
830 INT32 GetClassName32A( HWND32 hwnd, LPSTR buffer, INT32 count )
832 WND *wndPtr;
833 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
834 return GlobalGetAtomName32A( wndPtr->class->atomName, buffer, count );
838 /***********************************************************************
839 * GetClassName32W (USER32.217)
841 INT32 GetClassName32W( HWND32 hwnd, LPWSTR buffer, INT32 count )
843 WND *wndPtr;
844 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
845 return GlobalGetAtomName32W( wndPtr->class->atomName, buffer, count );
849 /***********************************************************************
850 * GetClassInfo16 (USER.404)
852 BOOL16 GetClassInfo16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASS16 *wc )
854 ATOM atom;
855 CLASS *classPtr;
857 hInstance = GetExePtr( hInstance );
858 if (!(atom = GlobalFindAtom16( name )) ||
859 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
860 (hInstance != classPtr->hInstance)) return FALSE;
861 wc->style = (UINT16)classPtr->style;
862 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, WIN_PROC_16 );
863 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
864 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
865 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
866 wc->hIcon = classPtr->hIcon;
867 wc->hCursor = classPtr->hCursor;
868 wc->hbrBackground = classPtr->hbrBackground;
869 wc->lpszClassName = (SEGPTR)0;
870 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
871 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
872 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
873 return TRUE;
877 /***********************************************************************
878 * GetClassInfo32A (USER32.210)
880 BOOL32 GetClassInfo32A( HINSTANCE32 hInstance, LPCSTR name, WNDCLASS32A *wc )
882 ATOM atom;
883 CLASS *classPtr;
885 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
886 if (!(atom = GlobalFindAtom32A( name )) ||
887 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
888 (hInstance != classPtr->hInstance)) return FALSE;
889 wc->style = classPtr->style;
890 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
891 WIN_PROC_32A );
892 wc->cbClsExtra = classPtr->cbClsExtra;
893 wc->cbWndExtra = classPtr->cbWndExtra;
894 wc->hInstance = classPtr->hInstance;
895 wc->hIcon = (HICON32)classPtr->hIcon;
896 wc->hCursor = (HCURSOR32)classPtr->hCursor;
897 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
898 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
899 wc->lpszClassName = NULL;
900 return TRUE;
904 /***********************************************************************
905 * GetClassInfo32W (USER32.213)
907 BOOL32 GetClassInfo32W( HINSTANCE32 hInstance, LPCWSTR name, WNDCLASS32W *wc )
909 ATOM atom;
910 CLASS *classPtr;
912 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
913 if (!(atom = GlobalFindAtom32W( name )) ||
914 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
915 (hInstance != classPtr->hInstance)) return FALSE;
916 wc->style = classPtr->style;
917 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
918 WIN_PROC_32W );
919 wc->cbClsExtra = classPtr->cbClsExtra;
920 wc->cbWndExtra = classPtr->cbWndExtra;
921 wc->hInstance = classPtr->hInstance;
922 wc->hIcon = (HICON32)classPtr->hIcon;
923 wc->hCursor = (HCURSOR32)classPtr->hCursor;
924 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
925 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
926 wc->lpszClassName = NULL;
927 return TRUE;
931 /***********************************************************************
932 * GetClassInfoEx16 (USER.398)
934 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
935 * same in Win16 as in Win32. --AJ
937 BOOL16 GetClassInfoEx16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASSEX16 *wc )
939 ATOM atom;
940 CLASS *classPtr;
942 hInstance = GetExePtr( hInstance );
943 if (!(atom = GlobalFindAtom16( name )) ||
944 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
945 (hInstance != classPtr->hInstance)) return FALSE;
946 wc->style = classPtr->style;
947 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, WIN_PROC_16 );
948 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
949 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
950 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
951 wc->hIcon = classPtr->hIcon;
952 wc->hIconSm = classPtr->hIconSm;
953 wc->hCursor = classPtr->hCursor;
954 wc->hbrBackground = classPtr->hbrBackground;
955 wc->lpszClassName = (SEGPTR)0;
956 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
957 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
958 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
959 return TRUE;
963 /***********************************************************************
964 * GetClassInfoEx32A (USER32.211)
966 BOOL32 GetClassInfoEx32A( HINSTANCE32 hInstance, LPCSTR name,
967 WNDCLASSEX32A *wc )
969 ATOM atom;
970 CLASS *classPtr;
972 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
973 if (!(atom = GlobalFindAtom32A( name )) ||
974 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
975 (hInstance != classPtr->hInstance)) return FALSE;
976 wc->style = classPtr->style;
977 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
978 WIN_PROC_32A );
979 wc->cbClsExtra = classPtr->cbClsExtra;
980 wc->cbWndExtra = classPtr->cbWndExtra;
981 wc->hInstance = classPtr->hInstance;
982 wc->hIcon = (HICON32)classPtr->hIcon;
983 wc->hIconSm = (HICON32)classPtr->hIconSm;
984 wc->hCursor = (HCURSOR32)classPtr->hCursor;
985 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
986 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
987 wc->lpszClassName = NULL;
988 return TRUE;
992 /***********************************************************************
993 * GetClassInfoEx32W (USER32.212)
995 BOOL32 GetClassInfoEx32W( HINSTANCE32 hInstance, LPCWSTR name,
996 WNDCLASSEX32W *wc )
998 ATOM atom;
999 CLASS *classPtr;
1001 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
1002 if (!(atom = GlobalFindAtom32W( name )) ||
1003 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1004 (hInstance != classPtr->hInstance)) return FALSE;
1005 wc->style = classPtr->style;
1006 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
1007 WIN_PROC_32W );
1008 wc->cbClsExtra = classPtr->cbClsExtra;
1009 wc->cbWndExtra = classPtr->cbWndExtra;
1010 wc->hInstance = classPtr->hInstance;
1011 wc->hIcon = (HICON32)classPtr->hIcon;
1012 wc->hIconSm = (HICON32)classPtr->hIconSm;
1013 wc->hCursor = (HCURSOR32)classPtr->hCursor;
1014 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
1015 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1016 wc->lpszClassName = NULL;
1017 return TRUE;
1021 /***********************************************************************
1022 * ClassFirst (TOOLHELP.69)
1024 BOOL16 ClassFirst( CLASSENTRY *pClassEntry )
1026 pClassEntry->wNext = 1;
1027 return ClassNext( pClassEntry );
1031 /***********************************************************************
1032 * ClassNext (TOOLHELP.70)
1034 BOOL16 ClassNext( CLASSENTRY *pClassEntry )
1036 int i;
1037 CLASS *class = firstClass;
1039 if (!pClassEntry->wNext) return FALSE;
1040 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1041 if (!class)
1043 pClassEntry->wNext = 0;
1044 return FALSE;
1046 pClassEntry->hInst = class->hInstance;
1047 pClassEntry->wNext++;
1048 GlobalGetAtomName32A( class->atomName, pClassEntry->szClassName,
1049 sizeof(pClassEntry->szClassName) );
1050 return TRUE;