2 * Window classes functions
4 * Copyright 1993, 1996 Alexandre Julliard
23 static CLASS
*firstClass
= NULL
;
26 /***********************************************************************
29 * Dump the content of a class structure to stderr.
31 void CLASS_DumpClass( CLASS
*ptr
)
36 if (ptr
->magic
!= CLASS_MAGIC
)
38 fprintf( stderr
, "%p is not a class\n", ptr
);
42 GlobalGetAtomName32A( ptr
->atomName
, className
, sizeof(className
) );
44 fprintf( stderr
, "Class %p:\n", ptr
);
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
);
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 /***********************************************************************
67 * Walk the class list and print each class on stderr.
69 void CLASS_WalkClasses(void)
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
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 /***********************************************************************
140 * Set the menu name in a class structure by copying the string.
142 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
146 CLASS_SetMenuNameA( classPtr
, (LPCSTR
)name
);
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 /***********************************************************************
161 * Free a class structure.
163 static BOOL
CLASS_FreeClass( CLASS
*classPtr
)
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;
177 fprintf(stderr
, "ERROR: Class list corrupted\n" );
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
);
194 /***********************************************************************
195 * CLASS_FreeModuleClasses
197 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
201 for (ptr
= firstClass
; ptr
; 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
)
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;
242 /***********************************************************************
243 * CLASS_FindClassByName
245 * Return a pointer to the class.
247 CLASS
*CLASS_FindClassByName( SEGPTR name
, HINSTANCE hinstance
)
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
)
268 /* Check if a class with this name already exists */
270 classPtr
= CLASS_FindClassByAtom( atom
, hInstance
);
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
;
316 /***********************************************************************
317 * RegisterClass16 (USER.57)
319 ATOM
RegisterClass16( const WNDCLASS16
*wc
)
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
);
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
);
351 /***********************************************************************
352 * RegisterClass32A (USER32.426)
354 ATOM
RegisterClass32A( const WNDCLASS32A
* wc
)
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
,
368 GlobalDeleteAtom( atom
);
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
);
386 /***********************************************************************
387 * RegisterClass32W (USER32.429)
389 ATOM
RegisterClass32W( const WNDCLASS32W
* wc
)
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
,
403 GlobalDeleteAtom( atom
);
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
);
421 /***********************************************************************
422 * RegisterClassEx16 (USER.397)
424 ATOM
RegisterClassEx16( const WNDCLASSEX16
*wc
)
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
);
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
);
456 /***********************************************************************
457 * RegisterClassEx32A (USER32.427)
459 ATOM
RegisterClassEx32A( const WNDCLASSEX32A
* wc
)
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
,
473 GlobalDeleteAtom( atom
);
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
);
491 /***********************************************************************
492 * RegisterClassEx32W (USER32.428)
494 ATOM
RegisterClassEx32W( const WNDCLASSEX32W
* wc
)
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
,
508 GlobalDeleteAtom( atom
);
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
);
526 /***********************************************************************
527 * UnregisterClass16 (USER.403)
529 BOOL16
UnregisterClass16( SEGPTR className
, HINSTANCE16 hInstance
)
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
)
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
)
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
)
581 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
584 if (offset
<= wndPtr
->class->cbClsExtra
- sizeof(WORD
))
585 return GET_WORD(((char *)wndPtr
->class->wExtra
) + 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
;
598 return (WORD
)GetClassLong32A( hwnd
, offset
);
600 fprintf(stderr
, "Warning: invalid offset %d for GetClassWord()\n", offset
);
605 /***********************************************************************
606 * GetClassLong16 (USER.131)
608 LONG
GetClassLong16( HWND16 hwnd
, INT16 offset
)
616 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
617 return (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_16
);
619 ret
= GetClassLong32A( hwnd
, offset
);
620 return (LONG
)SEGPTR_GET( (void *)ret
);
622 return GetClassLong32A( hwnd
, offset
);
627 /***********************************************************************
628 * GetClassLong32A (USER32.214)
630 LONG
GetClassLong32A( HWND32 hwnd
, INT32 offset
)
634 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
637 if (offset
<= wndPtr
->class->cbClsExtra
- sizeof(LONG
))
638 return GET_DWORD(((char *)wndPtr
->class->wExtra
) + 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
;
647 return (LONG
)WINPROC_GetProc(wndPtr
->class->winproc
, WIN_PROC_32A
);
649 return (LONG
)CLASS_GetMenuNameA( wndPtr
->class );
650 case GCL_HBRBACKGROUND
:
654 return GetClassWord( hwnd
, offset
);
656 fprintf(stderr
, "Warning: invalid offset %d for GetClassLong()\n", offset
);
661 /***********************************************************************
662 * GetClassLong32W (USER32.215)
664 LONG
GetClassLong32W( HWND32 hwnd
, INT32 offset
)
671 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
672 return (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_32W
);
674 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
675 return (LONG
)CLASS_GetMenuNameW( wndPtr
->class );
677 return GetClassLong32A( hwnd
, offset
);
682 /***********************************************************************
683 * SetClassWord (USER.130) (USER32.468)
685 WORD
SetClassWord( HWND32 hwnd
, INT32 offset
, WORD newval
)
691 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
694 if (offset
+ sizeof(WORD
) <= wndPtr
->class->cbClsExtra
)
695 ptr
= ((char *)wndPtr
->class->wExtra
) + offset
;
698 fprintf( stderr
, "Warning: invalid offset %d for SetClassWord()\n",
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;
716 fprintf( stderr
, "Warning: invalid offset %d for SetClassWord()\n",
720 retval
= GET_WORD(ptr
);
721 PUT_WORD( ptr
, newval
);
726 /***********************************************************************
727 * SetClassLong16 (USER.132)
729 LONG
SetClassLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
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
,
743 return SetClassLong32A( hwnd
, offset
, (LONG
)PTR_SEG_TO_LIN(newval
) );
745 return SetClassLong32A( hwnd
, offset
, newval
);
750 /***********************************************************************
751 * SetClassLong32A (USER32.466)
753 LONG
SetClassLong32A( HWND32 hwnd
, INT32 offset
, LONG newval
)
759 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
762 if (offset
+ sizeof(LONG
) <= wndPtr
->class->cbClsExtra
)
763 ptr
= ((char *)wndPtr
->class->wExtra
) + offset
;
766 fprintf( stderr
, "Warning: invalid offset %d for SetClassLong()\n",
774 CLASS_SetMenuNameA( wndPtr
->class, (LPCSTR
)newval
);
775 return 0; /* Old value is now meaningless anyway */
777 retval
= (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
,
779 WINPROC_SetProc( &wndPtr
->class->winproc
, (WNDPROC16
)newval
,
782 case GCL_HBRBACKGROUND
:
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;
792 fprintf( stderr
, "Warning: invalid offset %d for SetClassLong()\n",
796 retval
= GET_DWORD(ptr
);
797 PUT_DWORD( ptr
, newval
);
802 /***********************************************************************
803 * SetClassLong32W (USER32.467)
805 LONG
SetClassLong32W( HWND32 hwnd
, INT32 offset
, LONG newval
)
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
,
819 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
820 CLASS_SetMenuNameW( wndPtr
->class, (LPCWSTR
)newval
);
821 return 0; /* Old value is now meaningless anyway */
823 return SetClassLong32A( hwnd
, offset
, newval
);
828 /***********************************************************************
829 * GetClassName16 (USER.58)
831 INT16
GetClassName16( HWND16 hwnd
, LPSTR buffer
, INT16 count
)
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
)
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
)
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
)
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
);
889 /***********************************************************************
890 * GetClassInfo32A (USER32.210)
892 BOOL32
GetClassInfo32A( HINSTANCE32 hInstance
, LPCSTR name
, WNDCLASS32A
*wc
)
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
,
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
;
916 /***********************************************************************
917 * GetClassInfo32W (USER32.213)
919 BOOL32
GetClassInfo32W( HINSTANCE32 hInstance
, LPCWSTR name
, WNDCLASS32W
*wc
)
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
,
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
;
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
)
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
);
975 /***********************************************************************
976 * GetClassInfoEx32A (USER32.211)
978 BOOL32
GetClassInfoEx32A( HINSTANCE32 hInstance
, LPCSTR name
,
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
,
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
;
1004 /***********************************************************************
1005 * GetClassInfoEx32W (USER32.212)
1007 BOOL32
GetClassInfoEx32W( HINSTANCE32 hInstance
, LPCWSTR name
,
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
,
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
;
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
)
1049 CLASS
*class = firstClass
;
1051 if (!pClassEntry
->wNext
) return FALSE
;
1052 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1055 pClassEntry
->wNext
= 0;
1058 pClassEntry
->hInst
= class->hInstance
;
1059 pClassEntry
->wNext
++;
1060 GlobalGetAtomName32A( class->atomName
, pClassEntry
->szClassName
,
1061 sizeof(pClassEntry
->szClassName
) );