2 * Window classes functions
4 * Copyright 1993, 1996 Alexandre Julliard
6 * FIXME: In win32 all classes are local. They are registered at
7 * program start. Processes CANNOT share classes. (Source: some
8 * win31->NT migration book)
26 static CLASS
*firstClass
= NULL
;
29 /***********************************************************************
32 * Dump the content of a class structure to stderr.
34 void CLASS_DumpClass( CLASS
*ptr
)
39 if (ptr
->magic
!= CLASS_MAGIC
)
41 fprintf( stderr
, "%p is not a class\n", ptr
);
45 GlobalGetAtomName32A( ptr
->atomName
, className
, sizeof(className
) );
47 fprintf( stderr
, "Class %p:\n", ptr
);
49 "next=%p name=%04x '%s' style=%08x wndProc=%08x\n"
50 "inst=%04x dce=%08x icon=%04x cursor=%04x bkgnd=%04x\n"
51 "clsExtra=%d winExtra=%d #windows=%d\n",
52 ptr
->next
, ptr
->atomName
, className
, ptr
->style
,
53 (UINT32
)ptr
->winproc
, ptr
->hInstance
, (UINT32
)ptr
->dce
,
54 ptr
->hIcon
, ptr
->hCursor
, ptr
->hbrBackground
,
55 ptr
->cbClsExtra
, ptr
->cbWndExtra
, ptr
->cWindows
);
58 fprintf( stderr
, "extra bytes:" );
59 for (i
= 0; i
< ptr
->cbClsExtra
; i
++)
60 fprintf( stderr
, " %02x", *((BYTE
*)ptr
->wExtra
+i
) );
61 fprintf( stderr
, "\n" );
63 fprintf( stderr
, "\n" );
67 /***********************************************************************
70 * Walk the class list and print each class on stderr.
72 void CLASS_WalkClasses(void)
77 fprintf( stderr
, " Class Name Style WndProc\n" );
78 for (ptr
= firstClass
; ptr
; ptr
= ptr
->next
)
80 GlobalGetAtomName32A( ptr
->atomName
, className
, sizeof(className
) );
81 fprintf( stderr
, "%08x %-20.20s %08x %08x\n", (UINT32
)ptr
, className
,
82 ptr
->style
, (UINT32
)ptr
->winproc
);
84 fprintf( stderr
, "\n" );
88 /***********************************************************************
91 * Get the menu name as a ASCII string.
93 static LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
95 if (!classPtr
->menuNameA
&& classPtr
->menuNameW
)
97 /* We need to copy the Unicode string */
98 classPtr
->menuNameA
= SEGPTR_STRDUP_WtoA( classPtr
->menuNameW
);
100 return classPtr
->menuNameA
;
104 /***********************************************************************
107 * Get the menu name as a Unicode string.
109 static LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
111 if (!classPtr
->menuNameW
&& classPtr
->menuNameA
)
113 if (!HIWORD(classPtr
->menuNameA
))
114 return (LPWSTR
)classPtr
->menuNameA
;
115 /* Now we need to copy the ASCII string */
116 classPtr
->menuNameW
= HEAP_strdupAtoW( SystemHeap
, 0,
117 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 BOOL32
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
->dce
) DCE_FreeDCE( classPtr
->dce
);
185 if (classPtr
->hbrBackground
) DeleteObject32( classPtr
->hbrBackground
);
186 GlobalDeleteAtom( classPtr
->atomName
);
187 CLASS_SetMenuNameA( classPtr
, NULL
);
188 WINPROC_FreeProc( classPtr
->winproc
, WIN_PROC_CLASS
);
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.
213 * hinstance has been normalized by the caller.
215 CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE32 hinstance
)
219 /* First search task-specific classes */
221 for (class = firstClass
; (class); class = class->next
)
223 if (class->style
& CS_GLOBALCLASS
) continue;
224 if ((class->atomName
== atom
) &&
225 ((hinstance
== 0xffff) ||
226 (hinstance
== class->hInstance
))) return class;
229 /* Then search global classes */
231 for (class = firstClass
; (class); class = class->next
)
233 if (!(class->style
& CS_GLOBALCLASS
)) continue;
234 if (class->atomName
== atom
) return class;
241 /***********************************************************************
242 * CLASS_RegisterClass
244 * The real RegisterClass() functionality.
246 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE32 hInstance
,
247 DWORD style
, INT32 classExtra
,
248 INT32 winExtra
, WNDPROC16 wndProc
,
249 WINDOWPROCTYPE wndProcType
)
253 /* Check if a class with this name already exists */
255 classPtr
= CLASS_FindClassByAtom( atom
, hInstance
);
258 /* Class can be created only if it is local and */
259 /* if the class with the same name is global. */
261 if (style
& CS_GLOBALCLASS
) return NULL
;
262 if (!(classPtr
->style
& CS_GLOBALCLASS
)) return NULL
;
265 /* Fix the extra bytes value */
267 if (classExtra
< 0) classExtra
= 0;
268 else if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
269 fprintf(stderr
, "Warning: class extra bytes %d is > 40\n", classExtra
);
270 if (winExtra
< 0) winExtra
= 0;
271 else if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
272 fprintf( stderr
, "Warning: win extra bytes %d is > 40\n", winExtra
);
274 /* Create the class */
276 classPtr
= (CLASS
*)HeapAlloc( SystemHeap
, 0, sizeof(CLASS
) +
277 classExtra
- sizeof(classPtr
->wExtra
) );
278 if (!classPtr
) return NULL
;
279 classPtr
->next
= firstClass
;
280 classPtr
->magic
= CLASS_MAGIC
;
281 classPtr
->cWindows
= 0;
282 classPtr
->style
= style
;
283 classPtr
->winproc
= (HWINDOWPROC
)0;
284 classPtr
->cbWndExtra
= winExtra
;
285 classPtr
->cbClsExtra
= classExtra
;
286 classPtr
->hInstance
= hInstance
;
287 classPtr
->atomName
= atom
;
288 classPtr
->menuNameA
= 0;
289 classPtr
->menuNameW
= 0;
290 classPtr
->dce
= (style
& CS_CLASSDC
) ?
291 DCE_AllocDCE( 0, DCE_CLASS_DC
) : NULL
;
293 WINPROC_SetProc( &classPtr
->winproc
, wndProc
, wndProcType
, WIN_PROC_CLASS
);
295 /* Other values must be set by caller */
297 if (classExtra
) memset( classPtr
->wExtra
, 0, classExtra
);
298 firstClass
= classPtr
;
303 /***********************************************************************
304 * RegisterClass16 (USER.57)
306 ATOM WINAPI
RegisterClass16( const WNDCLASS16
*wc
)
310 HINSTANCE16 hInstance
=GetExePtr(wc
->hInstance
);
312 if (!(atom
= GlobalAddAtom16( wc
->lpszClassName
))) return 0;
313 if (!(classPtr
= CLASS_RegisterClass( atom
, hInstance
, wc
->style
,
314 wc
->cbClsExtra
, wc
->cbWndExtra
,
315 wc
->lpfnWndProc
, WIN_PROC_16
)))
317 GlobalDeleteAtom( atom
);
321 dprintf_class( stddeb
, "RegisterClass16: atom=%04x wndproc=%08lx hinst=%04x
322 bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
323 atom
, (DWORD
)wc
->lpfnWndProc
, hInstance
,
324 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
325 wc
->cbWndExtra
, classPtr
,
326 HIWORD(wc
->lpszClassName
) ?
327 (char *)PTR_SEG_TO_LIN(wc
->lpszClassName
) : "" );
329 classPtr
->hIcon
= wc
->hIcon
;
330 classPtr
->hIconSm
= 0;
331 classPtr
->hCursor
= wc
->hCursor
;
332 classPtr
->hbrBackground
= wc
->hbrBackground
;
334 CLASS_SetMenuNameA( classPtr
, HIWORD(wc
->lpszMenuName
) ?
335 PTR_SEG_TO_LIN(wc
->lpszMenuName
) : (LPCSTR
)wc
->lpszMenuName
);
340 /***********************************************************************
341 * RegisterClass32A (USER32.426)
343 ATOM WINAPI
RegisterClass32A( const WNDCLASS32A
* wc
)
348 if (!(atom
= GlobalAddAtom32A( wc
->lpszClassName
))) return 0;
349 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
350 wc
->cbClsExtra
, wc
->cbWndExtra
,
351 (WNDPROC16
)wc
->lpfnWndProc
,
354 GlobalDeleteAtom( atom
);
358 dprintf_class( stddeb
, "RegisterClass32A: atom=%04x wndproc=%08lx
359 hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
360 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
361 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
362 wc
->cbWndExtra
, classPtr
,
363 HIWORD(wc
->lpszClassName
) ? wc
->lpszClassName
: "" );
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
);
374 /***********************************************************************
375 * RegisterClass32W (USER32.429)
377 ATOM WINAPI
RegisterClass32W( const WNDCLASS32W
* wc
)
382 if (!(atom
= GlobalAddAtom32W( wc
->lpszClassName
))) return 0;
383 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
384 wc
->cbClsExtra
, wc
->cbWndExtra
,
385 (WNDPROC16
)wc
->lpfnWndProc
,
388 GlobalDeleteAtom( atom
);
392 dprintf_class( stddeb
, "RegisterClass32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
393 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
394 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
395 wc
->cbWndExtra
, classPtr
);
397 classPtr
->hIcon
= (HICON16
)wc
->hIcon
;
398 classPtr
->hIconSm
= 0;
399 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
400 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
401 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
406 /***********************************************************************
407 * RegisterClassEx16 (USER.397)
409 ATOM WINAPI
RegisterClassEx16( const WNDCLASSEX16
*wc
)
413 HINSTANCE16 hInstance
= 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
);
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
);
440 /***********************************************************************
441 * RegisterClassEx32A (USER32.427)
443 ATOM WINAPI
RegisterClassEx32A( const WNDCLASSEX32A
* wc
)
448 if (!(atom
= GlobalAddAtom32A( wc
->lpszClassName
))) return 0;
449 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
450 wc
->cbClsExtra
, wc
->cbWndExtra
,
451 (WNDPROC16
)wc
->lpfnWndProc
,
454 GlobalDeleteAtom( atom
);
458 dprintf_class( stddeb
, "RegisterClassEx32A: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
459 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
460 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
461 wc
->cbWndExtra
, classPtr
);
463 classPtr
->hIcon
= (HICON16
)wc
->hIcon
;
464 classPtr
->hIconSm
= (HICON16
)wc
->hIconSm
;
465 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
466 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
467 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
472 /***********************************************************************
473 * RegisterClassEx32W (USER32.428)
475 ATOM WINAPI
RegisterClassEx32W( const WNDCLASSEX32W
* wc
)
480 if (!(atom
= GlobalAddAtom32W( wc
->lpszClassName
))) return 0;
481 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
482 wc
->cbClsExtra
, wc
->cbWndExtra
,
483 (WNDPROC16
)wc
->lpfnWndProc
,
486 GlobalDeleteAtom( atom
);
490 dprintf_class( stddeb
, "RegisterClassEx32W: atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
491 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
492 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
493 wc
->cbWndExtra
, classPtr
);
495 classPtr
->hIcon
= (HICON16
)wc
->hIcon
;
496 classPtr
->hIconSm
= (HICON16
)wc
->hIconSm
;
497 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
498 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
499 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
504 /***********************************************************************
505 * UnregisterClass16 (USER.403)
507 BOOL16 WINAPI
UnregisterClass16( SEGPTR className
, HINSTANCE16 hInstance
)
512 hInstance
= GetExePtr( hInstance
);
513 if (!(atom
= GlobalFindAtom16( className
))) return FALSE
;
514 if (!(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
515 (classPtr
->hInstance
!= hInstance
)) return FALSE
;
516 return CLASS_FreeClass( classPtr
);
520 /***********************************************************************
521 * UnregisterClass32A (USER32.562)
523 BOOL32 WINAPI
UnregisterClass32A( LPCSTR className
, HINSTANCE32 hInstance
)
528 if (!(atom
= GlobalFindAtom32A( className
))) return FALSE
;
529 if (!(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
530 (classPtr
->hInstance
!= hInstance
)) return FALSE
;
531 return CLASS_FreeClass( classPtr
);
535 /***********************************************************************
536 * UnregisterClass32W (USER32.563)
538 BOOL32 WINAPI
UnregisterClass32W( LPCWSTR className
, HINSTANCE32 hInstance
)
543 if (!(atom
= GlobalFindAtom32W( className
))) return FALSE
;
544 if (!(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
545 (classPtr
->hInstance
!= hInstance
)) return FALSE
;
546 return CLASS_FreeClass( classPtr
);
550 /***********************************************************************
551 * GetClassWord16 (USER.129)
553 WORD WINAPI
GetClassWord16( HWND16 hwnd
, INT16 offset
)
555 return GetClassWord32( hwnd
, offset
);
559 /***********************************************************************
560 * GetClassWord32 (USER32.218)
562 WORD WINAPI
GetClassWord32( HWND32 hwnd
, INT32 offset
)
566 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
569 if (offset
<= wndPtr
->class->cbClsExtra
- sizeof(WORD
))
570 return GET_WORD(((char *)wndPtr
->class->wExtra
) + offset
);
574 case GCW_HBRBACKGROUND
: return wndPtr
->class->hbrBackground
;
575 case GCW_HCURSOR
: return wndPtr
->class->hCursor
;
576 case GCW_HICON
: return wndPtr
->class->hIcon
;
577 case GCW_HICONSM
: return wndPtr
->class->hIconSm
;
578 case GCW_ATOM
: return wndPtr
->class->atomName
;
583 return (WORD
)GetClassLong32A( hwnd
, offset
);
585 fprintf(stderr
, "Warning: invalid offset %d for GetClassWord()\n", offset
);
590 /***********************************************************************
591 * GetClassLong16 (USER.131)
593 LONG WINAPI
GetClassLong16( HWND16 hwnd
, INT16 offset
)
601 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
602 return (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_16
);
604 ret
= GetClassLong32A( hwnd
, offset
);
605 return (LONG
)SEGPTR_GET( (void *)ret
);
607 return GetClassLong32A( hwnd
, offset
);
612 /***********************************************************************
613 * GetClassLong32A (USER32.214)
615 LONG WINAPI
GetClassLong32A( HWND32 hwnd
, INT32 offset
)
619 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
622 if (offset
<= wndPtr
->class->cbClsExtra
- sizeof(LONG
))
623 return GET_DWORD(((char *)wndPtr
->class->wExtra
) + offset
);
627 case GCL_STYLE
: return (LONG
)wndPtr
->class->style
;
628 case GCL_CBWNDEXTRA
: return (LONG
)wndPtr
->class->cbWndExtra
;
629 case GCL_CBCLSEXTRA
: return (LONG
)wndPtr
->class->cbClsExtra
;
630 case GCL_HMODULE
: return (LONG
)wndPtr
->class->hInstance
;
632 return (LONG
)WINPROC_GetProc(wndPtr
->class->winproc
, WIN_PROC_32A
);
634 return (LONG
)CLASS_GetMenuNameA( wndPtr
->class );
635 case GCL_HBRBACKGROUND
:
639 return GetClassWord32( hwnd
, offset
);
641 fprintf(stderr
, "Warning: invalid offset %d for GetClassLong()\n", offset
);
646 /***********************************************************************
647 * GetClassLong32W (USER32.215)
649 LONG WINAPI
GetClassLong32W( HWND32 hwnd
, INT32 offset
)
656 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
657 return (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_32W
);
659 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
660 return (LONG
)CLASS_GetMenuNameW( wndPtr
->class );
662 return GetClassLong32A( hwnd
, offset
);
667 /***********************************************************************
668 * SetClassWord16 (USER.130)
670 WORD WINAPI
SetClassWord16( HWND16 hwnd
, INT16 offset
, WORD newval
)
672 return SetClassWord32( hwnd
, offset
, newval
);
676 /***********************************************************************
677 * SetClassWord32 (USER32.468)
679 WORD WINAPI
SetClassWord32( HWND32 hwnd
, INT32 offset
, WORD newval
)
685 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
688 if (offset
+ sizeof(WORD
) <= wndPtr
->class->cbClsExtra
)
689 ptr
= ((char *)wndPtr
->class->wExtra
) + offset
;
692 fprintf( stderr
, "Warning: invalid offset %d for SetClassWord()\n",
703 return (WORD
)SetClassLong32A( hwnd
, offset
, (LONG
)newval
);
704 case GCW_HBRBACKGROUND
: ptr
= &wndPtr
->class->hbrBackground
; break;
705 case GCW_HCURSOR
: ptr
= &wndPtr
->class->hCursor
; break;
706 case GCW_HICON
: ptr
= &wndPtr
->class->hIcon
; break;
707 case GCW_HICONSM
: ptr
= &wndPtr
->class->hIconSm
; break;
708 case GCW_ATOM
: ptr
= &wndPtr
->class->atomName
; break;
710 fprintf( stderr
, "Warning: invalid offset %d for SetClassWord()\n",
714 retval
= GET_WORD(ptr
);
715 PUT_WORD( ptr
, newval
);
720 /***********************************************************************
721 * SetClassLong16 (USER.132)
723 LONG WINAPI
SetClassLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
731 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
732 retval
= (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_16
);
733 WINPROC_SetProc( &wndPtr
->class->winproc
, (WNDPROC16
)newval
,
734 WIN_PROC_16
, WIN_PROC_CLASS
);
737 return SetClassLong32A( hwnd
, offset
, (LONG
)PTR_SEG_TO_LIN(newval
) );
739 return SetClassLong32A( hwnd
, offset
, newval
);
744 /***********************************************************************
745 * SetClassLong32A (USER32.466)
747 LONG WINAPI
SetClassLong32A( HWND32 hwnd
, INT32 offset
, LONG newval
)
753 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
756 if (offset
+ sizeof(LONG
) <= wndPtr
->class->cbClsExtra
)
757 ptr
= ((char *)wndPtr
->class->wExtra
) + offset
;
760 fprintf( stderr
, "Warning: invalid offset %d for SetClassLong()\n",
768 CLASS_SetMenuNameA( wndPtr
->class, (LPCSTR
)newval
);
769 return 0; /* Old value is now meaningless anyway */
771 retval
= (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
,
773 WINPROC_SetProc( &wndPtr
->class->winproc
, (WNDPROC16
)newval
,
774 WIN_PROC_32A
, WIN_PROC_CLASS
);
776 case GCL_HBRBACKGROUND
:
780 return SetClassWord32( hwnd
, offset
, (WORD
)newval
);
781 case GCL_STYLE
: ptr
= &wndPtr
->class->style
; break;
782 case GCL_CBWNDEXTRA
: ptr
= &wndPtr
->class->cbWndExtra
; break;
783 case GCL_CBCLSEXTRA
: ptr
= &wndPtr
->class->cbClsExtra
; break;
784 case GCL_HMODULE
: ptr
= &wndPtr
->class->hInstance
; break;
786 fprintf( stderr
, "Warning: invalid offset %d for SetClassLong()\n",
790 retval
= GET_DWORD(ptr
);
791 PUT_DWORD( ptr
, newval
);
796 /***********************************************************************
797 * SetClassLong32W (USER32.467)
799 LONG WINAPI
SetClassLong32W( HWND32 hwnd
, INT32 offset
, LONG newval
)
807 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
808 retval
= (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_32W
);
809 WINPROC_SetProc( &wndPtr
->class->winproc
, (WNDPROC16
)newval
,
810 WIN_PROC_32W
, WIN_PROC_CLASS
);
813 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
814 CLASS_SetMenuNameW( wndPtr
->class, (LPCWSTR
)newval
);
815 return 0; /* Old value is now meaningless anyway */
817 return SetClassLong32A( hwnd
, offset
, newval
);
822 /***********************************************************************
823 * GetClassName16 (USER.58)
825 INT16 WINAPI
GetClassName16( HWND16 hwnd
, LPSTR buffer
, INT16 count
)
828 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
829 return GlobalGetAtomName16( wndPtr
->class->atomName
, buffer
, count
);
833 /***********************************************************************
834 * GetClassName32A (USER32.216)
836 INT32 WINAPI
GetClassName32A( HWND32 hwnd
, LPSTR buffer
, INT32 count
)
839 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
840 return GlobalGetAtomName32A( wndPtr
->class->atomName
, buffer
, count
);
844 /***********************************************************************
845 * GetClassName32W (USER32.217)
847 INT32 WINAPI
GetClassName32W( HWND32 hwnd
, LPWSTR buffer
, INT32 count
)
850 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
851 return GlobalGetAtomName32W( wndPtr
->class->atomName
, buffer
, count
);
855 /***********************************************************************
856 * GetClassInfo16 (USER.404)
858 BOOL16 WINAPI
GetClassInfo16( HINSTANCE16 hInstance
, SEGPTR name
,
864 hInstance
= GetExePtr( hInstance
);
865 if (!(atom
= GlobalFindAtom16( name
)) ||
866 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
868 if ((hInstance
!= classPtr
->hInstance
) &&
869 !(classPtr
->style
& CS_GLOBALCLASS
)) /*BWCC likes to pass hInstance=0*/
871 wc
->style
= (UINT16
)classPtr
->style
;
872 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, WIN_PROC_16
);
873 wc
->cbClsExtra
= (INT16
)classPtr
->cbClsExtra
;
874 wc
->cbWndExtra
= (INT16
)classPtr
->cbWndExtra
;
875 wc
->hInstance
= (HINSTANCE16
)classPtr
->hInstance
;
876 wc
->hIcon
= classPtr
->hIcon
;
877 wc
->hCursor
= classPtr
->hCursor
;
878 wc
->hbrBackground
= classPtr
->hbrBackground
;
879 wc
->lpszClassName
= (SEGPTR
)0;
880 wc
->lpszMenuName
= (SEGPTR
)CLASS_GetMenuNameA( classPtr
);
881 if (HIWORD(wc
->lpszMenuName
)) /* Make it a SEGPTR */
882 wc
->lpszMenuName
= SEGPTR_GET( (LPSTR
)wc
->lpszMenuName
);
887 /***********************************************************************
888 * GetClassInfo32A (USER32.210)
890 BOOL32 WINAPI
GetClassInfo32A( HINSTANCE32 hInstance
, LPCSTR name
,
896 if (!(atom
= GlobalFindAtom32A( name
)) ||
897 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
898 (classPtr
->hInstance
&& (hInstance
!= classPtr
->hInstance
)))
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 WINAPI
GetClassInfo32W( HINSTANCE32 hInstance
, LPCWSTR name
,
925 if (!(atom
= GlobalFindAtom32W( name
)) ||
926 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
927 (classPtr
->hInstance
&& (hInstance
!= classPtr
->hInstance
)))
930 wc
->style
= classPtr
->style
;
931 wc
->lpfnWndProc
= (WNDPROC32
)WINPROC_GetProc( classPtr
->winproc
,
933 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
934 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
935 wc
->hInstance
= classPtr
->hInstance
;
936 wc
->hIcon
= (HICON32
)classPtr
->hIcon
;
937 wc
->hCursor
= (HCURSOR32
)classPtr
->hCursor
;
938 wc
->hbrBackground
= (HBRUSH32
)classPtr
->hbrBackground
;
939 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
940 wc
->lpszClassName
= NULL
;
945 /***********************************************************************
946 * GetClassInfoEx16 (USER.398)
948 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
949 * same in Win16 as in Win32. --AJ
951 BOOL16 WINAPI
GetClassInfoEx16( HINSTANCE16 hInstance
, SEGPTR name
,
957 hInstance
= GetExePtr( hInstance
);
958 if (!(atom
= GlobalFindAtom16( name
)) ||
959 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
960 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
961 wc
->style
= classPtr
->style
;
962 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, WIN_PROC_16
);
963 wc
->cbClsExtra
= (INT16
)classPtr
->cbClsExtra
;
964 wc
->cbWndExtra
= (INT16
)classPtr
->cbWndExtra
;
965 wc
->hInstance
= (HINSTANCE16
)classPtr
->hInstance
;
966 wc
->hIcon
= classPtr
->hIcon
;
967 wc
->hIconSm
= classPtr
->hIconSm
;
968 wc
->hCursor
= classPtr
->hCursor
;
969 wc
->hbrBackground
= classPtr
->hbrBackground
;
970 wc
->lpszClassName
= (SEGPTR
)0;
971 wc
->lpszMenuName
= (SEGPTR
)CLASS_GetMenuNameA( classPtr
);
972 if (HIWORD(wc
->lpszMenuName
)) /* Make it a SEGPTR */
973 wc
->lpszMenuName
= SEGPTR_GET( (LPSTR
)wc
->lpszMenuName
);
978 /***********************************************************************
979 * GetClassInfoEx32A (USER32.211)
981 BOOL32 WINAPI
GetClassInfoEx32A( HINSTANCE32 hInstance
, LPCSTR name
,
987 if (!(atom
= GlobalFindAtom32A( name
)) ||
988 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
989 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
990 wc
->style
= classPtr
->style
;
991 wc
->lpfnWndProc
= (WNDPROC32
)WINPROC_GetProc( classPtr
->winproc
,
993 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
994 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
995 wc
->hInstance
= classPtr
->hInstance
;
996 wc
->hIcon
= (HICON32
)classPtr
->hIcon
;
997 wc
->hIconSm
= (HICON32
)classPtr
->hIconSm
;
998 wc
->hCursor
= (HCURSOR32
)classPtr
->hCursor
;
999 wc
->hbrBackground
= (HBRUSH32
)classPtr
->hbrBackground
;
1000 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1001 wc
->lpszClassName
= NULL
;
1006 /***********************************************************************
1007 * GetClassInfoEx32W (USER32.212)
1009 BOOL32 WINAPI
GetClassInfoEx32W( HINSTANCE32 hInstance
, LPCWSTR name
,
1015 if (!(atom
= GlobalFindAtom32W( name
)) ||
1016 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
1017 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
1018 wc
->style
= classPtr
->style
;
1019 wc
->lpfnWndProc
= (WNDPROC32
)WINPROC_GetProc( classPtr
->winproc
,
1021 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1022 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1023 wc
->hInstance
= classPtr
->hInstance
;
1024 wc
->hIcon
= (HICON32
)classPtr
->hIcon
;
1025 wc
->hIconSm
= (HICON32
)classPtr
->hIconSm
;
1026 wc
->hCursor
= (HCURSOR32
)classPtr
->hCursor
;
1027 wc
->hbrBackground
= (HBRUSH32
)classPtr
->hbrBackground
;
1028 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1029 wc
->lpszClassName
= NULL
;
1034 /***********************************************************************
1035 * ClassFirst (TOOLHELP.69)
1037 BOOL16 WINAPI
ClassFirst( CLASSENTRY
*pClassEntry
)
1039 pClassEntry
->wNext
= 1;
1040 return ClassNext( pClassEntry
);
1044 /***********************************************************************
1045 * ClassNext (TOOLHELP.70)
1047 BOOL16 WINAPI
ClassNext( CLASSENTRY
*pClassEntry
)
1050 CLASS
*class = firstClass
;
1052 if (!pClassEntry
->wNext
) return FALSE
;
1053 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1056 pClassEntry
->wNext
= 0;
1059 pClassEntry
->hInst
= class->hInstance
;
1060 pClassEntry
->wNext
++;
1061 GlobalGetAtomName32A( class->atomName
, pClassEntry
->szClassName
,
1062 sizeof(pClassEntry
->szClassName
) );