Release 961222
[wine/multimedia.git] / windows / class.c
blobd04e707362e1cd301b8fb65ca71ab4bab9e9d837
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 "toolhelp.h"
17 #include "winproc.h"
18 #include "stddebug.h"
19 #include "debug.h"
22 static CLASS *firstClass = NULL;
25 /***********************************************************************
26 * CLASS_DumpClass
28 * Dump the content of a class structure to stderr.
30 void CLASS_DumpClass( CLASS *ptr )
32 char className[80];
33 int i;
35 if (ptr->magic != CLASS_MAGIC)
37 fprintf( stderr, "%p is not a class\n", ptr );
38 return;
41 GlobalGetAtomName32A( ptr->atomName, className, sizeof(className) );
43 fprintf( stderr, "Class %p:\n", ptr );
44 fprintf( stderr,
45 "next=%p name=%04x '%s' style=%08x wndProc=%08x\n"
46 "inst=%04x dce=%08x icon=%04x cursor=%04x bkgnd=%04x\n"
47 "clsExtra=%d winExtra=%d #windows=%d\n",
48 ptr->next, ptr->atomName, className, ptr->style,
49 (UINT32)ptr->winproc, ptr->hInstance, (UINT32)ptr->dce,
50 ptr->hIcon, ptr->hCursor, ptr->hbrBackground,
51 ptr->cbClsExtra, ptr->cbWndExtra, ptr->cWindows );
52 if (ptr->cbClsExtra)
54 fprintf( stderr, "extra bytes:" );
55 for (i = 0; i < ptr->cbClsExtra; i++)
56 fprintf( stderr, " %02x", *((BYTE *)ptr->wExtra+i) );
57 fprintf( stderr, "\n" );
59 fprintf( stderr, "\n" );
63 /***********************************************************************
64 * CLASS_WalkClasses
66 * Walk the class list and print each class on stderr.
68 void CLASS_WalkClasses(void)
70 CLASS *ptr;
71 char className[80];
73 fprintf( stderr, " Class Name Style WndProc\n" );
74 for (ptr = firstClass; ptr; ptr = ptr->next)
76 GlobalGetAtomName32A( ptr->atomName, className, sizeof(className) );
77 fprintf( stderr, "%08x %-20.20s %08x %08x\n", (UINT32)ptr, className,
78 ptr->style, (UINT32)ptr->winproc );
80 fprintf( stderr, "\n" );
84 /***********************************************************************
85 * CLASS_GetMenuNameA
87 * Get the menu name as a ASCII string.
89 static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
91 if (!classPtr->menuNameA && classPtr->menuNameW)
93 /* We need to copy the Unicode string */
94 classPtr->menuNameA = SEGPTR_STRDUP_WtoA( classPtr->menuNameW );
96 return classPtr->menuNameA;
100 /***********************************************************************
101 * CLASS_GetMenuNameW
103 * Get the menu name as a Unicode string.
105 static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
107 if (!classPtr->menuNameW && classPtr->menuNameA)
109 if (!HIWORD(classPtr->menuNameA))
110 return (LPWSTR)classPtr->menuNameA;
111 /* Now we need to copy the ASCII string */
112 classPtr->menuNameW = HEAP_strdupAtoW( SystemHeap, 0,
113 classPtr->menuNameA );
115 return classPtr->menuNameW;
119 /***********************************************************************
120 * CLASS_SetMenuNameA
122 * Set the menu name in a class structure by copying the string.
124 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
126 if (HIWORD(classPtr->menuNameA)) SEGPTR_FREE( classPtr->menuNameA );
127 if (classPtr->menuNameW) HeapFree( SystemHeap, 0, classPtr->menuNameW );
128 classPtr->menuNameA = SEGPTR_STRDUP( name );
129 classPtr->menuNameW = 0;
133 /***********************************************************************
134 * CLASS_SetMenuNameW
136 * Set the menu name in a class structure by copying the string.
138 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
140 if (!HIWORD(name))
142 CLASS_SetMenuNameA( classPtr, (LPCSTR)name );
143 return;
145 if (HIWORD(classPtr->menuNameA)) SEGPTR_FREE( classPtr->menuNameA );
146 if (classPtr->menuNameW) HeapFree( SystemHeap, 0, classPtr->menuNameW );
147 if ((classPtr->menuNameW = HeapAlloc( SystemHeap, 0,
148 (lstrlen32W(name)+1)*sizeof(WCHAR) )))
149 lstrcpy32W( classPtr->menuNameW, name );
150 classPtr->menuNameA = 0;
154 /***********************************************************************
155 * CLASS_FreeClass
157 * Free a class structure.
159 static BOOL CLASS_FreeClass( CLASS *classPtr )
161 CLASS **ppClass;
163 /* Check if we can remove this class */
165 if (classPtr->cWindows > 0) return FALSE;
167 /* Remove the class from the linked list */
169 for (ppClass = &firstClass; *ppClass; ppClass = &(*ppClass)->next)
170 if (*ppClass == classPtr) break;
171 if (!*ppClass)
173 fprintf(stderr, "ERROR: Class list corrupted\n" );
174 return FALSE;
176 *ppClass = classPtr->next;
178 /* Delete the class */
180 if (classPtr->dce) DCE_FreeDCE( classPtr->dce );
181 if (classPtr->hbrBackground) DeleteObject32( classPtr->hbrBackground );
182 GlobalDeleteAtom( classPtr->atomName );
183 CLASS_SetMenuNameA( classPtr, NULL );
184 WINPROC_FreeProc( classPtr->winproc );
185 HeapFree( SystemHeap, 0, classPtr );
186 return TRUE;
190 /***********************************************************************
191 * CLASS_FreeModuleClasses
193 void CLASS_FreeModuleClasses( HMODULE16 hModule )
195 CLASS *ptr, *next;
197 for (ptr = firstClass; ptr; ptr = next)
199 next = ptr->next;
200 if (ptr->hInstance == hModule) CLASS_FreeClass( ptr );
205 /***********************************************************************
206 * CLASS_FindClassByAtom
208 * Return a pointer to the class.
210 CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE16 hinstance )
212 CLASS * class;
214 if (hinstance != 0xffff) hinstance = GetExePtr(hinstance);
216 /* First search task-specific classes */
218 for (class = firstClass; (class); class = class->next)
220 if (class->style & CS_GLOBALCLASS) continue;
221 if ((class->atomName == atom) &&
222 ((hinstance == 0xffff) ||
223 (hinstance == class->hInstance))) return class;
226 /* Then search global classes */
228 for (class = firstClass; (class); class = class->next)
230 if (!(class->style & CS_GLOBALCLASS)) continue;
231 if (class->atomName == atom) return class;
234 return 0;
238 /***********************************************************************
239 * CLASS_RegisterClass
241 * The real RegisterClass() functionality.
243 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE32 hInstance,
244 DWORD style, INT32 classExtra,
245 INT32 winExtra, WNDPROC16 wndProc,
246 WINDOWPROCTYPE wndProcType )
248 CLASS *classPtr;
250 /* Check if a class with this name already exists */
252 classPtr = CLASS_FindClassByAtom( atom, hInstance );
253 if (classPtr)
255 /* Class can be created only if it is local and */
256 /* if the class with the same name is global. */
258 if (style & CS_GLOBALCLASS) return NULL;
259 if (!(classPtr->style & CS_GLOBALCLASS)) return NULL;
262 /* Fix the extra bytes value */
264 if (classExtra < 0) classExtra = 0;
265 else if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
266 fprintf(stderr, "Warning: class extra bytes %d is > 40\n", classExtra);
267 if (winExtra < 0) winExtra = 0;
268 else if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
269 fprintf( stderr, "Warning: win extra bytes %d is > 40\n", winExtra );
271 /* Create the class */
273 classPtr = (CLASS *)HeapAlloc( SystemHeap, 0, sizeof(CLASS) +
274 classExtra - sizeof(classPtr->wExtra) );
275 if (!classPtr) return NULL;
276 classPtr->next = firstClass;
277 classPtr->magic = CLASS_MAGIC;
278 classPtr->cWindows = 0;
279 classPtr->style = style;
280 classPtr->winproc = (HWINDOWPROC)0;
281 classPtr->cbWndExtra = winExtra;
282 classPtr->cbClsExtra = classExtra;
283 classPtr->hInstance = hInstance;
284 classPtr->atomName = atom;
285 classPtr->menuNameA = 0;
286 classPtr->menuNameW = 0;
287 classPtr->dce = (style & CS_CLASSDC) ?
288 DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
290 WINPROC_SetProc( &classPtr->winproc, wndProc, wndProcType );
292 /* Other values must be set by caller */
294 if (classExtra) memset( classPtr->wExtra, 0, classExtra );
295 firstClass = classPtr;
296 return classPtr;
300 /***********************************************************************
301 * RegisterClass16 (USER.57)
303 ATOM RegisterClass16( const WNDCLASS16 *wc )
305 ATOM atom;
306 CLASS *classPtr;
308 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
310 if (!(atom = GlobalAddAtom16( wc->lpszClassName ))) return 0;
311 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
312 wc->cbClsExtra, wc->cbWndExtra,
313 wc->lpfnWndProc, WIN_PROC_16 )))
315 GlobalDeleteAtom( atom );
316 return 0;
319 dprintf_class( stddeb, "RegisterClass16: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
320 atom, (DWORD)wc->lpfnWndProc, hInstance,
321 wc->hbrBackground, wc->style, wc->cbClsExtra,
322 wc->cbWndExtra, classPtr );
324 classPtr->hIcon = wc->hIcon;
325 classPtr->hIconSm = 0;
326 classPtr->hCursor = wc->hCursor;
327 classPtr->hbrBackground = wc->hbrBackground;
329 CLASS_SetMenuNameA( classPtr, HIWORD(wc->lpszMenuName) ?
330 PTR_SEG_TO_LIN(wc->lpszMenuName) : (LPCSTR)wc->lpszMenuName );
331 return atom;
335 /***********************************************************************
336 * RegisterClass32A (USER32.426)
338 ATOM RegisterClass32A( const WNDCLASS32A* wc )
340 ATOM atom;
341 CLASS *classPtr;
343 /* FIXME: this should not be necessary for Win32 */
344 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
346 if (!(atom = GlobalAddAtom32A( wc->lpszClassName ))) return 0;
347 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
348 wc->cbClsExtra, wc->cbWndExtra,
349 (WNDPROC16)wc->lpfnWndProc,
350 WIN_PROC_32A )))
352 GlobalDeleteAtom( atom );
353 return 0;
356 dprintf_class( stddeb, "RegisterClass32A: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
357 atom, (DWORD)wc->lpfnWndProc, hInstance,
358 wc->hbrBackground, wc->style, wc->cbClsExtra,
359 wc->cbWndExtra, classPtr );
361 classPtr->hIcon = (HICON16)wc->hIcon;
362 classPtr->hIconSm = 0;
363 classPtr->hCursor = (HCURSOR16)wc->hCursor;
364 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
365 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
366 return atom;
370 /***********************************************************************
371 * RegisterClass32W (USER32.429)
373 ATOM RegisterClass32W( const WNDCLASS32W* wc )
375 ATOM atom;
376 CLASS *classPtr;
378 /* FIXME: this should not be necessary for Win32 */
379 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
381 if (!(atom = GlobalAddAtom32W( wc->lpszClassName ))) return 0;
382 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
383 wc->cbClsExtra, wc->cbWndExtra,
384 (WNDPROC16)wc->lpfnWndProc,
385 WIN_PROC_32W )))
387 GlobalDeleteAtom( atom );
388 return 0;
391 dprintf_class( stddeb, "RegisterClass32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
392 atom, (DWORD)wc->lpfnWndProc, hInstance,
393 wc->hbrBackground, wc->style, wc->cbClsExtra,
394 wc->cbWndExtra, classPtr );
396 classPtr->hIcon = (HICON16)wc->hIcon;
397 classPtr->hIconSm = 0;
398 classPtr->hCursor = (HCURSOR16)wc->hCursor;
399 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
400 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
401 return atom;
405 /***********************************************************************
406 * RegisterClassEx16 (USER.397)
408 ATOM RegisterClassEx16( const WNDCLASSEX16 *wc )
410 ATOM atom;
411 CLASS *classPtr;
413 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
415 if (!(atom = GlobalAddAtom16( wc->lpszClassName ))) return 0;
416 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
417 wc->cbClsExtra, wc->cbWndExtra,
418 wc->lpfnWndProc, WIN_PROC_16 )))
420 GlobalDeleteAtom( atom );
421 return 0;
424 dprintf_class( stddeb, "RegisterClassEx16: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
425 atom, (DWORD)wc->lpfnWndProc, hInstance,
426 wc->hbrBackground, wc->style, wc->cbClsExtra,
427 wc->cbWndExtra, classPtr );
429 classPtr->hIcon = wc->hIcon;
430 classPtr->hIconSm = wc->hIconSm;
431 classPtr->hCursor = wc->hCursor;
432 classPtr->hbrBackground = wc->hbrBackground;
434 CLASS_SetMenuNameA( classPtr, HIWORD(wc->lpszMenuName) ?
435 PTR_SEG_TO_LIN(wc->lpszMenuName) : (LPCSTR)wc->lpszMenuName );
436 return atom;
440 /***********************************************************************
441 * RegisterClassEx32A (USER32.427)
443 ATOM RegisterClassEx32A( const WNDCLASSEX32A* wc )
445 ATOM atom;
446 CLASS *classPtr;
448 /* FIXME: this should not be necessary for Win32 */
449 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
451 if (!(atom = GlobalAddAtom32A( wc->lpszClassName ))) return 0;
452 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
453 wc->cbClsExtra, wc->cbWndExtra,
454 (WNDPROC16)wc->lpfnWndProc,
455 WIN_PROC_32A )))
457 GlobalDeleteAtom( atom );
458 return 0;
461 dprintf_class( stddeb, "RegisterClassEx32A: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
462 atom, (DWORD)wc->lpfnWndProc, hInstance,
463 wc->hbrBackground, wc->style, wc->cbClsExtra,
464 wc->cbWndExtra, classPtr );
466 classPtr->hIcon = (HICON16)wc->hIcon;
467 classPtr->hIconSm = (HICON16)wc->hIconSm;
468 classPtr->hCursor = (HCURSOR16)wc->hCursor;
469 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
470 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
471 return atom;
475 /***********************************************************************
476 * RegisterClassEx32W (USER32.428)
478 ATOM RegisterClassEx32W( const WNDCLASSEX32W* wc )
480 ATOM atom;
481 CLASS *classPtr;
483 /* FIXME: this should not be necessary for Win32 */
484 HINSTANCE32 hInstance = (HINSTANCE32)GetExePtr( wc->hInstance );
486 if (!(atom = GlobalAddAtom32W( wc->lpszClassName ))) return 0;
487 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
488 wc->cbClsExtra, wc->cbWndExtra,
489 (WNDPROC16)wc->lpfnWndProc,
490 WIN_PROC_32W )))
492 GlobalDeleteAtom( atom );
493 return 0;
496 dprintf_class( stddeb, "RegisterClassEx32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
497 atom, (DWORD)wc->lpfnWndProc, hInstance,
498 wc->hbrBackground, wc->style, wc->cbClsExtra,
499 wc->cbWndExtra, classPtr );
501 classPtr->hIcon = (HICON16)wc->hIcon;
502 classPtr->hIconSm = (HICON16)wc->hIconSm;
503 classPtr->hCursor = (HCURSOR16)wc->hCursor;
504 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
505 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
506 return atom;
510 /***********************************************************************
511 * UnregisterClass16 (USER.403)
513 BOOL16 UnregisterClass16( SEGPTR className, HINSTANCE16 hInstance )
515 CLASS *classPtr;
516 ATOM atom;
518 hInstance = GetExePtr( hInstance );
519 if (!(atom = GlobalFindAtom16( className ))) return FALSE;
520 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
521 (classPtr->hInstance != hInstance)) return FALSE;
522 return CLASS_FreeClass( classPtr );
526 /***********************************************************************
527 * UnregisterClass32A (USER32.562)
529 BOOL32 UnregisterClass32A( LPCSTR className, HINSTANCE32 hInstance )
531 CLASS *classPtr;
532 ATOM atom;
534 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
535 if (!(atom = GlobalFindAtom32A( className ))) return FALSE;
536 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
537 (classPtr->hInstance != hInstance)) return FALSE;
538 return CLASS_FreeClass( classPtr );
542 /***********************************************************************
543 * UnregisterClass32W (USER32.563)
545 BOOL32 UnregisterClass32W( LPCWSTR className, HINSTANCE32 hInstance )
547 CLASS *classPtr;
548 ATOM atom;
550 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
551 if (!(atom = GlobalFindAtom32W( className ))) return FALSE;
552 if (!(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
553 (classPtr->hInstance != hInstance)) return FALSE;
554 return CLASS_FreeClass( classPtr );
558 /***********************************************************************
559 * GetClassWord (USER.129) (USER32.218)
561 WORD GetClassWord( HWND32 hwnd, INT32 offset )
563 WND * wndPtr;
565 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
566 if (offset >= 0)
568 if (offset <= wndPtr->class->cbClsExtra - sizeof(WORD))
569 return GET_WORD(((char *)wndPtr->class->wExtra) + offset);
571 else switch(offset)
573 case GCW_HBRBACKGROUND: return wndPtr->class->hbrBackground;
574 case GCW_HCURSOR: return wndPtr->class->hCursor;
575 case GCW_HICON: return wndPtr->class->hIcon;
576 case GCW_HICONSM: return wndPtr->class->hIconSm;
577 case GCW_ATOM: return wndPtr->class->atomName;
578 case GCW_STYLE:
579 case GCW_CBWNDEXTRA:
580 case GCW_CBCLSEXTRA:
581 case GCW_HMODULE:
582 return (WORD)GetClassLong32A( hwnd, offset );
584 fprintf(stderr, "Warning: invalid offset %d for GetClassWord()\n", offset);
585 return 0;
589 /***********************************************************************
590 * GetClassLong16 (USER.131)
592 LONG GetClassLong16( HWND16 hwnd, INT16 offset )
594 WND *wndPtr;
595 LONG ret;
597 switch( offset )
599 case GCL_WNDPROC:
600 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
601 return (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_16 );
602 case GCL_MENUNAME:
603 ret = GetClassLong32A( hwnd, offset );
604 return (LONG)SEGPTR_GET( (void *)ret );
605 default:
606 return GetClassLong32A( hwnd, offset );
611 /***********************************************************************
612 * GetClassLong32A (USER32.214)
614 LONG GetClassLong32A( HWND32 hwnd, INT32 offset )
616 WND * wndPtr;
618 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
619 if (offset >= 0)
621 if (offset <= wndPtr->class->cbClsExtra - sizeof(LONG))
622 return GET_DWORD(((char *)wndPtr->class->wExtra) + offset);
624 switch(offset)
626 case GCL_STYLE: return (LONG)wndPtr->class->style;
627 case GCL_CBWNDEXTRA: return (LONG)wndPtr->class->cbWndExtra;
628 case GCL_CBCLSEXTRA: return (LONG)wndPtr->class->cbClsExtra;
629 case GCL_HMODULE: return (LONG)wndPtr->class->hInstance;
630 case GCL_WNDPROC:
631 return (LONG)WINPROC_GetProc(wndPtr->class->winproc, WIN_PROC_32A);
632 case GCL_MENUNAME:
633 return (LONG)CLASS_GetMenuNameA( wndPtr->class );
634 case GCL_HBRBACKGROUND:
635 case GCL_HCURSOR:
636 case GCL_HICON:
637 case GCL_HICONSM:
638 return GetClassWord( hwnd, offset );
640 fprintf(stderr, "Warning: invalid offset %d for GetClassLong()\n", offset);
641 return 0;
645 /***********************************************************************
646 * GetClassLong32W (USER32.215)
648 LONG GetClassLong32W( HWND32 hwnd, INT32 offset )
650 WND * wndPtr;
652 switch(offset)
654 case GCL_WNDPROC:
655 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
656 return (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_32W );
657 case GCL_MENUNAME:
658 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
659 return (LONG)CLASS_GetMenuNameW( wndPtr->class );
660 default:
661 return GetClassLong32A( hwnd, offset );
666 /***********************************************************************
667 * SetClassWord (USER.130) (USER32.468)
669 WORD SetClassWord( HWND32 hwnd, INT32 offset, WORD newval )
671 WND * wndPtr;
672 WORD retval = 0;
673 void *ptr;
675 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
676 if (offset >= 0)
678 if (offset + sizeof(WORD) <= wndPtr->class->cbClsExtra)
679 ptr = ((char *)wndPtr->class->wExtra) + offset;
680 else
682 fprintf( stderr, "Warning: invalid offset %d for SetClassWord()\n",
683 offset );
684 return 0;
687 else switch(offset)
689 case GCW_STYLE:
690 case GCW_CBWNDEXTRA:
691 case GCW_CBCLSEXTRA:
692 case GCW_HMODULE:
693 return (WORD)SetClassLong32A( hwnd, offset, (LONG)newval );
694 case GCW_HBRBACKGROUND: ptr = &wndPtr->class->hbrBackground; break;
695 case GCW_HCURSOR: ptr = &wndPtr->class->hCursor; break;
696 case GCW_HICON: ptr = &wndPtr->class->hIcon; break;
697 case GCW_HICONSM: ptr = &wndPtr->class->hIconSm; break;
698 case GCW_ATOM: ptr = &wndPtr->class->atomName; break;
699 default:
700 fprintf( stderr, "Warning: invalid offset %d for SetClassWord()\n",
701 offset);
702 return 0;
704 retval = GET_WORD(ptr);
705 PUT_WORD( ptr, newval );
706 return retval;
710 /***********************************************************************
711 * SetClassLong16 (USER.132)
713 LONG SetClassLong16( HWND16 hwnd, INT16 offset, LONG newval )
715 WND *wndPtr;
716 LONG retval;
718 switch(offset)
720 case GCL_WNDPROC:
721 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
722 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_16 );
723 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
724 WIN_PROC_16 );
725 return retval;
726 case GCL_MENUNAME:
727 return SetClassLong32A( hwnd, offset, (LONG)PTR_SEG_TO_LIN(newval) );
728 default:
729 return SetClassLong32A( hwnd, offset, newval );
734 /***********************************************************************
735 * SetClassLong32A (USER32.466)
737 LONG SetClassLong32A( HWND32 hwnd, INT32 offset, LONG newval )
739 WND * wndPtr;
740 LONG retval = 0;
741 void *ptr;
743 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
744 if (offset >= 0)
746 if (offset + sizeof(LONG) <= wndPtr->class->cbClsExtra)
747 ptr = ((char *)wndPtr->class->wExtra) + offset;
748 else
750 fprintf( stderr, "Warning: invalid offset %d for SetClassLong()\n",
751 offset );
752 return 0;
755 else switch(offset)
757 case GCL_MENUNAME:
758 CLASS_SetMenuNameA( wndPtr->class, (LPCSTR)newval );
759 return 0; /* Old value is now meaningless anyway */
760 case GCL_WNDPROC:
761 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc,
762 WIN_PROC_32A );
763 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
764 WIN_PROC_32A );
765 return retval;
766 case GCL_HBRBACKGROUND:
767 case GCL_HCURSOR:
768 case GCL_HICON:
769 case GCL_HICONSM:
770 return SetClassWord( hwnd, offset, (WORD)newval );
771 case GCL_STYLE: ptr = &wndPtr->class->style; break;
772 case GCL_CBWNDEXTRA: ptr = &wndPtr->class->cbWndExtra; break;
773 case GCL_CBCLSEXTRA: ptr = &wndPtr->class->cbClsExtra; break;
774 case GCL_HMODULE: ptr = &wndPtr->class->hInstance; break;
775 default:
776 fprintf( stderr, "Warning: invalid offset %d for SetClassLong()\n",
777 offset);
778 return 0;
780 retval = GET_DWORD(ptr);
781 PUT_DWORD( ptr, newval );
782 return retval;
786 /***********************************************************************
787 * SetClassLong32W (USER32.467)
789 LONG SetClassLong32W( HWND32 hwnd, INT32 offset, LONG newval )
791 WND *wndPtr;
792 LONG retval;
794 switch(offset)
796 case GCL_WNDPROC:
797 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
798 retval = (LONG)WINPROC_GetProc( wndPtr->class->winproc, WIN_PROC_32W );
799 WINPROC_SetProc( &wndPtr->class->winproc, (WNDPROC16)newval,
800 WIN_PROC_32W );
801 return retval;
802 case GCL_MENUNAME:
803 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
804 CLASS_SetMenuNameW( wndPtr->class, (LPCWSTR)newval );
805 return 0; /* Old value is now meaningless anyway */
806 default:
807 return SetClassLong32A( hwnd, offset, newval );
812 /***********************************************************************
813 * GetClassName16 (USER.58)
815 INT16 GetClassName16( HWND16 hwnd, LPSTR buffer, INT16 count )
817 WND *wndPtr;
818 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
819 return GlobalGetAtomName16( wndPtr->class->atomName, buffer, count );
823 /***********************************************************************
824 * GetClassName32A (USER32.216)
826 INT32 GetClassName32A( HWND32 hwnd, LPSTR buffer, INT32 count )
828 WND *wndPtr;
829 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
830 return GlobalGetAtomName32A( wndPtr->class->atomName, buffer, count );
834 /***********************************************************************
835 * GetClassName32W (USER32.217)
837 INT32 GetClassName32W( HWND32 hwnd, LPWSTR buffer, INT32 count )
839 WND *wndPtr;
840 if (!(wndPtr = WIN_FindWndPtr(hwnd))) return 0;
841 return GlobalGetAtomName32W( wndPtr->class->atomName, buffer, count );
845 /***********************************************************************
846 * GetClassInfo16 (USER.404)
848 BOOL16 GetClassInfo16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASS16 *wc )
850 ATOM atom;
851 CLASS *classPtr;
853 hInstance = GetExePtr( hInstance );
854 if (!(atom = GlobalFindAtom16( name )) ||
855 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
856 (hInstance != classPtr->hInstance)) return FALSE;
857 wc->style = (UINT16)classPtr->style;
858 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, WIN_PROC_16 );
859 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
860 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
861 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
862 wc->hIcon = classPtr->hIcon;
863 wc->hCursor = classPtr->hCursor;
864 wc->hbrBackground = classPtr->hbrBackground;
865 wc->lpszClassName = (SEGPTR)0;
866 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
867 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
868 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
869 return TRUE;
873 /***********************************************************************
874 * GetClassInfo32A (USER32.210)
876 BOOL32 GetClassInfo32A( HINSTANCE32 hInstance, LPCSTR name, WNDCLASS32A *wc )
878 ATOM atom;
879 CLASS *classPtr;
881 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
882 if (!(atom = GlobalFindAtom32A( name )) ||
883 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
884 (hInstance != classPtr->hInstance)) return FALSE;
885 wc->style = classPtr->style;
886 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
887 WIN_PROC_32A );
888 wc->cbClsExtra = classPtr->cbClsExtra;
889 wc->cbWndExtra = classPtr->cbWndExtra;
890 wc->hInstance = classPtr->hInstance;
891 wc->hIcon = (HICON32)classPtr->hIcon;
892 wc->hCursor = (HCURSOR32)classPtr->hCursor;
893 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
894 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
895 wc->lpszClassName = NULL;
896 return TRUE;
900 /***********************************************************************
901 * GetClassInfo32W (USER32.213)
903 BOOL32 GetClassInfo32W( HINSTANCE32 hInstance, LPCWSTR name, WNDCLASS32W *wc )
905 ATOM atom;
906 CLASS *classPtr;
908 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
909 if (!(atom = GlobalFindAtom32W( name )) ||
910 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
911 (hInstance != classPtr->hInstance)) return FALSE;
912 wc->style = classPtr->style;
913 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
914 WIN_PROC_32W );
915 wc->cbClsExtra = classPtr->cbClsExtra;
916 wc->cbWndExtra = classPtr->cbWndExtra;
917 wc->hInstance = classPtr->hInstance;
918 wc->hIcon = (HICON32)classPtr->hIcon;
919 wc->hCursor = (HCURSOR32)classPtr->hCursor;
920 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
921 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
922 wc->lpszClassName = NULL;
923 return TRUE;
927 /***********************************************************************
928 * GetClassInfoEx16 (USER.398)
930 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
931 * same in Win16 as in Win32. --AJ
933 BOOL16 GetClassInfoEx16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASSEX16 *wc )
935 ATOM atom;
936 CLASS *classPtr;
938 hInstance = GetExePtr( hInstance );
939 if (!(atom = GlobalFindAtom16( name )) ||
940 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
941 (hInstance != classPtr->hInstance)) return FALSE;
942 wc->style = classPtr->style;
943 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, WIN_PROC_16 );
944 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
945 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
946 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
947 wc->hIcon = classPtr->hIcon;
948 wc->hIconSm = classPtr->hIconSm;
949 wc->hCursor = classPtr->hCursor;
950 wc->hbrBackground = classPtr->hbrBackground;
951 wc->lpszClassName = (SEGPTR)0;
952 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
953 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
954 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
955 return TRUE;
959 /***********************************************************************
960 * GetClassInfoEx32A (USER32.211)
962 BOOL32 GetClassInfoEx32A( HINSTANCE32 hInstance, LPCSTR name,
963 WNDCLASSEX32A *wc )
965 ATOM atom;
966 CLASS *classPtr;
968 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
969 if (!(atom = GlobalFindAtom32A( name )) ||
970 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
971 (hInstance != classPtr->hInstance)) return FALSE;
972 wc->style = classPtr->style;
973 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
974 WIN_PROC_32A );
975 wc->cbClsExtra = classPtr->cbClsExtra;
976 wc->cbWndExtra = classPtr->cbWndExtra;
977 wc->hInstance = classPtr->hInstance;
978 wc->hIcon = (HICON32)classPtr->hIcon;
979 wc->hIconSm = (HICON32)classPtr->hIconSm;
980 wc->hCursor = (HCURSOR32)classPtr->hCursor;
981 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
982 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
983 wc->lpszClassName = NULL;
984 return TRUE;
988 /***********************************************************************
989 * GetClassInfoEx32W (USER32.212)
991 BOOL32 GetClassInfoEx32W( HINSTANCE32 hInstance, LPCWSTR name,
992 WNDCLASSEX32W *wc )
994 ATOM atom;
995 CLASS *classPtr;
997 hInstance = GetExePtr( hInstance ); /* FIXME: not needed in Win32 */
998 if (!(atom = GlobalFindAtom32W( name )) ||
999 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1000 (hInstance != classPtr->hInstance)) return FALSE;
1001 wc->style = classPtr->style;
1002 wc->lpfnWndProc = (WNDPROC32)WINPROC_GetProc( classPtr->winproc,
1003 WIN_PROC_32W );
1004 wc->cbClsExtra = classPtr->cbClsExtra;
1005 wc->cbWndExtra = classPtr->cbWndExtra;
1006 wc->hInstance = classPtr->hInstance;
1007 wc->hIcon = (HICON32)classPtr->hIcon;
1008 wc->hIconSm = (HICON32)classPtr->hIconSm;
1009 wc->hCursor = (HCURSOR32)classPtr->hCursor;
1010 wc->hbrBackground = (HBRUSH32)classPtr->hbrBackground;
1011 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1012 wc->lpszClassName = NULL;
1013 return TRUE;
1017 /***********************************************************************
1018 * ClassFirst (TOOLHELP.69)
1020 BOOL16 ClassFirst( CLASSENTRY *pClassEntry )
1022 pClassEntry->wNext = 1;
1023 return ClassNext( pClassEntry );
1027 /***********************************************************************
1028 * ClassNext (TOOLHELP.70)
1030 BOOL16 ClassNext( CLASSENTRY *pClassEntry )
1032 int i;
1033 CLASS *class = firstClass;
1035 if (!pClassEntry->wNext) return FALSE;
1036 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1037 if (!class)
1039 pClassEntry->wNext = 0;
1040 return FALSE;
1042 pClassEntry->hInst = class->hInstance;
1043 pClassEntry->wNext++;
1044 GlobalGetAtomName32A( class->atomName, pClassEntry->szClassName,
1045 sizeof(pClassEntry->szClassName) );
1046 return TRUE;