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)
25 static CLASS
*firstClass
= NULL
;
28 /***********************************************************************
31 * Dump the content of a class structure to stderr.
33 void CLASS_DumpClass( CLASS
*ptr
)
38 if (ptr
->magic
!= CLASS_MAGIC
)
40 fprintf( stderr
, "%p is not a class\n", ptr
);
44 GlobalGetAtomName32A( ptr
->atomName
, className
, sizeof(className
) );
46 fprintf( stderr
, "Class %p:\n", ptr
);
48 "next=%p name=%04x '%s' style=%08x wndProc=%08x\n"
49 "inst=%04x dce=%08x icon=%04x cursor=%04x bkgnd=%04x\n"
50 "clsExtra=%d winExtra=%d #windows=%d\n",
51 ptr
->next
, ptr
->atomName
, className
, ptr
->style
,
52 (UINT32
)ptr
->winproc
, ptr
->hInstance
, (UINT32
)ptr
->dce
,
53 ptr
->hIcon
, ptr
->hCursor
, ptr
->hbrBackground
,
54 ptr
->cbClsExtra
, ptr
->cbWndExtra
, ptr
->cWindows
);
57 fprintf( stderr
, "extra bytes:" );
58 for (i
= 0; i
< ptr
->cbClsExtra
; i
++)
59 fprintf( stderr
, " %02x", *((BYTE
*)ptr
->wExtra
+i
) );
60 fprintf( stderr
, "\n" );
62 fprintf( stderr
, "\n" );
66 /***********************************************************************
69 * Walk the class list and print each class on stderr.
71 void CLASS_WalkClasses(void)
76 fprintf( stderr
, " Class Name Style WndProc\n" );
77 for (ptr
= firstClass
; ptr
; ptr
= ptr
->next
)
79 GlobalGetAtomName32A( ptr
->atomName
, className
, sizeof(className
) );
80 fprintf( stderr
, "%08x %-20.20s %08x %08x\n", (UINT32
)ptr
, className
,
81 ptr
->style
, (UINT32
)ptr
->winproc
);
83 fprintf( stderr
, "\n" );
87 /***********************************************************************
90 * Get the menu name as a ASCII string.
92 static LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
94 if (!classPtr
->menuNameA
&& classPtr
->menuNameW
)
96 /* We need to copy the Unicode string */
97 classPtr
->menuNameA
= SEGPTR_STRDUP_WtoA( 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 classPtr
->menuNameW
= HEAP_strdupAtoW( SystemHeap
, 0,
116 classPtr
->menuNameA
);
118 return classPtr
->menuNameW
;
122 /***********************************************************************
125 * Set the menu name in a class structure by copying the string.
127 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
129 if (HIWORD(classPtr
->menuNameA
)) SEGPTR_FREE( classPtr
->menuNameA
);
130 if (classPtr
->menuNameW
) HeapFree( SystemHeap
, 0, classPtr
->menuNameW
);
131 classPtr
->menuNameA
= SEGPTR_STRDUP( name
);
132 classPtr
->menuNameW
= 0;
136 /***********************************************************************
139 * Set the menu name in a class structure by copying the string.
141 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
145 CLASS_SetMenuNameA( classPtr
, (LPCSTR
)name
);
148 if (HIWORD(classPtr
->menuNameA
)) SEGPTR_FREE( classPtr
->menuNameA
);
149 if (classPtr
->menuNameW
) HeapFree( SystemHeap
, 0, classPtr
->menuNameW
);
150 if ((classPtr
->menuNameW
= HeapAlloc( SystemHeap
, 0,
151 (lstrlen32W(name
)+1)*sizeof(WCHAR
) )))
152 lstrcpy32W( classPtr
->menuNameW
, name
);
153 classPtr
->menuNameA
= 0;
157 /***********************************************************************
160 * Free a class structure.
162 static BOOL32
CLASS_FreeClass( CLASS
*classPtr
)
166 /* Check if we can remove this class */
168 if (classPtr
->cWindows
> 0) return FALSE
;
170 /* Remove the class from the linked list */
172 for (ppClass
= &firstClass
; *ppClass
; ppClass
= &(*ppClass
)->next
)
173 if (*ppClass
== classPtr
) break;
176 fprintf(stderr
, "ERROR: Class list corrupted\n" );
179 *ppClass
= classPtr
->next
;
181 /* Delete the class */
183 if (classPtr
->dce
) DCE_FreeDCE( classPtr
->dce
);
184 if (classPtr
->hbrBackground
) DeleteObject32( classPtr
->hbrBackground
);
185 GlobalDeleteAtom( classPtr
->atomName
);
186 CLASS_SetMenuNameA( classPtr
, NULL
);
187 WINPROC_FreeProc( classPtr
->winproc
, WIN_PROC_CLASS
);
188 HeapFree( SystemHeap
, 0, classPtr
);
193 /***********************************************************************
194 * CLASS_FreeModuleClasses
196 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
200 for (ptr
= firstClass
; ptr
; ptr
= next
)
203 if (ptr
->hInstance
== hModule
) CLASS_FreeClass( ptr
);
208 /***********************************************************************
209 * CLASS_FindClassByAtom
211 * Return a pointer to the class.
212 * hinstance has been normalized by the caller.
214 CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE32 hinstance
)
218 /* First search task-specific classes */
220 for (class = firstClass
; (class); class = class->next
)
222 if (class->style
& CS_GLOBALCLASS
) continue;
223 if ((class->atomName
== atom
) &&
224 ((hinstance
== 0xffff) ||
225 (hinstance
== class->hInstance
))) return class;
228 /* Then search global classes */
230 for (class = firstClass
; (class); class = class->next
)
232 if (!(class->style
& CS_GLOBALCLASS
)) continue;
233 if (class->atomName
== atom
) return class;
240 /***********************************************************************
241 * CLASS_RegisterClass
243 * The real RegisterClass() functionality.
245 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE32 hInstance
,
246 DWORD style
, INT32 classExtra
,
247 INT32 winExtra
, WNDPROC16 wndProc
,
248 WINDOWPROCTYPE wndProcType
)
252 /* Check if a class with this name already exists */
254 classPtr
= CLASS_FindClassByAtom( atom
, hInstance
);
257 /* Class can be created only if it is local and */
258 /* if the class with the same name is global. */
260 if (style
& CS_GLOBALCLASS
) return NULL
;
261 if (!(classPtr
->style
& CS_GLOBALCLASS
)) return NULL
;
264 /* Fix the extra bytes value */
266 if (classExtra
< 0) classExtra
= 0;
267 else if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
268 fprintf(stderr
, "Warning: class extra bytes %d is > 40\n", classExtra
);
269 if (winExtra
< 0) winExtra
= 0;
270 else if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
271 fprintf( stderr
, "Warning: win extra bytes %d is > 40\n", winExtra
);
273 /* Create the class */
275 classPtr
= (CLASS
*)HeapAlloc( SystemHeap
, 0, sizeof(CLASS
) +
276 classExtra
- sizeof(classPtr
->wExtra
) );
277 if (!classPtr
) return NULL
;
278 classPtr
->next
= firstClass
;
279 classPtr
->magic
= CLASS_MAGIC
;
280 classPtr
->cWindows
= 0;
281 classPtr
->style
= style
;
282 classPtr
->winproc
= (HWINDOWPROC
)0;
283 classPtr
->cbWndExtra
= winExtra
;
284 classPtr
->cbClsExtra
= classExtra
;
285 classPtr
->hInstance
= hInstance
;
286 classPtr
->atomName
= atom
;
287 classPtr
->menuNameA
= 0;
288 classPtr
->menuNameW
= 0;
289 classPtr
->dce
= (style
& CS_CLASSDC
) ?
290 DCE_AllocDCE( 0, DCE_CLASS_DC
) : NULL
;
292 WINPROC_SetProc( &classPtr
->winproc
, wndProc
, wndProcType
, WIN_PROC_CLASS
);
294 /* Other values must be set by caller */
296 if (classExtra
) memset( classPtr
->wExtra
, 0, classExtra
);
297 firstClass
= classPtr
;
302 /***********************************************************************
303 * RegisterClass16 (USER.57)
305 ATOM WINAPI
RegisterClass16( const WNDCLASS16
*wc
)
309 HINSTANCE16 hInstance
=GetExePtr(wc
->hInstance
);
311 if (!(atom
= GlobalAddAtom16( wc
->lpszClassName
))) return 0;
312 if (!(classPtr
= CLASS_RegisterClass( atom
, hInstance
, wc
->style
,
313 wc
->cbClsExtra
, wc
->cbWndExtra
,
314 wc
->lpfnWndProc
, WIN_PROC_16
)))
316 GlobalDeleteAtom( atom
);
320 TRACE(class, "atom=%04x wndproc=%08lx hinst=%04x
321 bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
322 atom
, (DWORD
)wc
->lpfnWndProc
, hInstance
,
323 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
324 wc
->cbWndExtra
, classPtr
,
325 HIWORD(wc
->lpszClassName
) ?
326 (char *)PTR_SEG_TO_LIN(wc
->lpszClassName
) : "" );
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
);
339 /***********************************************************************
340 * RegisterClass32A (USER32.427)
342 * >0: Unique identifier
345 ATOM WINAPI
RegisterClass32A(
346 const WNDCLASS32A
* wc
/* Address of structure with class data */
351 if (!(atom
= GlobalAddAtom32A( wc
->lpszClassName
))) return 0;
352 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
353 wc
->cbClsExtra
, wc
->cbWndExtra
,
354 (WNDPROC16
)wc
->lpfnWndProc
,
357 GlobalDeleteAtom( atom
);
361 TRACE(class, "atom=%04x wndproc=%08lx
362 hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
363 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
364 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
365 wc
->cbWndExtra
, classPtr
,
366 HIWORD(wc
->lpszClassName
) ? wc
->lpszClassName
: "" );
368 classPtr
->hIcon
= (HICON16
)wc
->hIcon
;
369 classPtr
->hIconSm
= 0;
370 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
371 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
372 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
377 /***********************************************************************
378 * RegisterClass32W (USER32.430)
380 ATOM WINAPI
RegisterClass32W( const WNDCLASS32W
* wc
)
385 if (!(atom
= GlobalAddAtom32W( wc
->lpszClassName
))) return 0;
386 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
387 wc
->cbClsExtra
, wc
->cbWndExtra
,
388 (WNDPROC16
)wc
->lpfnWndProc
,
391 GlobalDeleteAtom( atom
);
395 TRACE(class, "atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
396 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->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
);
409 /***********************************************************************
410 * RegisterClassEx16 (USER.397)
412 ATOM WINAPI
RegisterClassEx16( const WNDCLASSEX16
*wc
)
416 HINSTANCE16 hInstance
= GetExePtr( wc
->hInstance
);
418 if (!(atom
= GlobalAddAtom16( wc
->lpszClassName
))) return 0;
419 if (!(classPtr
= CLASS_RegisterClass( atom
, hInstance
, wc
->style
,
420 wc
->cbClsExtra
, wc
->cbWndExtra
,
421 wc
->lpfnWndProc
, WIN_PROC_16
)))
423 GlobalDeleteAtom( atom
);
427 TRACE(class, "atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
428 atom
, (DWORD
)wc
->lpfnWndProc
, hInstance
,
429 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
430 wc
->cbWndExtra
, classPtr
);
432 classPtr
->hIcon
= wc
->hIcon
;
433 classPtr
->hIconSm
= wc
->hIconSm
;
434 classPtr
->hCursor
= wc
->hCursor
;
435 classPtr
->hbrBackground
= wc
->hbrBackground
;
437 CLASS_SetMenuNameA( classPtr
, HIWORD(wc
->lpszMenuName
) ?
438 PTR_SEG_TO_LIN(wc
->lpszMenuName
) : (LPCSTR
)wc
->lpszMenuName
);
443 /***********************************************************************
444 * RegisterClassEx32A (USER32.428)
446 ATOM WINAPI
RegisterClassEx32A( const WNDCLASSEX32A
* wc
)
451 if (!(atom
= GlobalAddAtom32A( wc
->lpszClassName
))) return 0;
452 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
453 wc
->cbClsExtra
, wc
->cbWndExtra
,
454 (WNDPROC16
)wc
->lpfnWndProc
,
457 GlobalDeleteAtom( atom
);
461 TRACE(class, "atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
462 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->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
);
475 /***********************************************************************
476 * RegisterClassEx32W (USER32.429)
478 ATOM WINAPI
RegisterClassEx32W( const WNDCLASSEX32W
* wc
)
483 if (!(atom
= GlobalAddAtom32W( wc
->lpszClassName
))) return 0;
484 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
485 wc
->cbClsExtra
, wc
->cbWndExtra
,
486 (WNDPROC16
)wc
->lpfnWndProc
,
489 GlobalDeleteAtom( atom
);
493 TRACE(class, "atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
494 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
495 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
496 wc
->cbWndExtra
, classPtr
);
498 classPtr
->hIcon
= (HICON16
)wc
->hIcon
;
499 classPtr
->hIconSm
= (HICON16
)wc
->hIconSm
;
500 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
501 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
502 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
507 /***********************************************************************
508 * UnregisterClass16 (USER.403)
510 BOOL16 WINAPI
UnregisterClass16( SEGPTR className
, HINSTANCE16 hInstance
)
515 hInstance
= GetExePtr( hInstance
);
516 if (!(atom
= GlobalFindAtom16( className
))) return FALSE
;
517 if (!(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
518 (classPtr
->hInstance
!= hInstance
)) return FALSE
;
519 return CLASS_FreeClass( classPtr
);
523 /***********************************************************************
524 * UnregisterClass32A (USER32.563)
526 BOOL32 WINAPI
UnregisterClass32A( LPCSTR className
, HINSTANCE32 hInstance
)
531 if (!(atom
= GlobalFindAtom32A( className
))) return FALSE
;
532 if (!(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
533 (classPtr
->hInstance
!= hInstance
)) return FALSE
;
534 return CLASS_FreeClass( classPtr
);
538 /***********************************************************************
539 * UnregisterClass32W (USER32.564)
541 BOOL32 WINAPI
UnregisterClass32W( LPCWSTR className
, HINSTANCE32 hInstance
)
546 if (!(atom
= GlobalFindAtom32W( className
))) return FALSE
;
547 if (!(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
548 (classPtr
->hInstance
!= hInstance
)) return FALSE
;
549 return CLASS_FreeClass( classPtr
);
553 /***********************************************************************
554 * GetClassWord16 (USER.129)
556 WORD WINAPI
GetClassWord16( HWND16 hwnd
, INT16 offset
)
558 return GetClassWord32( hwnd
, offset
);
562 /***********************************************************************
563 * GetClassWord32 (USER32.219)
565 WORD WINAPI
GetClassWord32( HWND32 hwnd
, INT32 offset
)
569 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
572 if (offset
<= wndPtr
->class->cbClsExtra
- sizeof(WORD
))
573 return GET_WORD(((char *)wndPtr
->class->wExtra
) + 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
;
586 return (WORD
)GetClassLong32A( hwnd
, offset
);
588 fprintf(stderr
, "Warning: invalid offset %d for GetClassWord()\n", offset
);
593 /***********************************************************************
594 * GetClassLong16 (USER.131)
596 LONG WINAPI
GetClassLong16( HWND16 hwnd
, INT16 offset
)
604 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
605 return (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_16
);
607 ret
= GetClassLong32A( hwnd
, offset
);
608 return (LONG
)SEGPTR_GET( (void *)ret
);
610 return GetClassLong32A( hwnd
, offset
);
615 /***********************************************************************
616 * GetClassLong32A (USER32.215)
618 LONG WINAPI
GetClassLong32A( HWND32 hwnd
, INT32 offset
)
622 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
625 if (offset
<= wndPtr
->class->cbClsExtra
- sizeof(LONG
))
626 return GET_DWORD(((char *)wndPtr
->class->wExtra
) + 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
;
635 return (LONG
)WINPROC_GetProc(wndPtr
->class->winproc
, WIN_PROC_32A
);
637 return (LONG
)CLASS_GetMenuNameA( wndPtr
->class );
638 case GCL_HBRBACKGROUND
:
642 return GetClassWord32( hwnd
, offset
);
644 fprintf(stderr
, "Warning: invalid offset %d for GetClassLong()\n", offset
);
649 /***********************************************************************
650 * GetClassLong32W (USER32.216)
652 LONG WINAPI
GetClassLong32W( HWND32 hwnd
, INT32 offset
)
659 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
660 return (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_32W
);
662 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
663 return (LONG
)CLASS_GetMenuNameW( wndPtr
->class );
665 return GetClassLong32A( hwnd
, offset
);
670 /***********************************************************************
671 * SetClassWord16 (USER.130)
673 WORD WINAPI
SetClassWord16( HWND16 hwnd
, INT16 offset
, WORD newval
)
675 return SetClassWord32( hwnd
, offset
, newval
);
679 /***********************************************************************
680 * SetClassWord32 (USER32.469)
682 WORD WINAPI
SetClassWord32( HWND32 hwnd
, INT32 offset
, WORD newval
)
688 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
691 if (offset
+ sizeof(WORD
) <= wndPtr
->class->cbClsExtra
)
692 ptr
= ((char *)wndPtr
->class->wExtra
) + offset
;
695 fprintf( stderr
, "Warning: invalid offset %d for SetClassWord()\n",
706 return (WORD
)SetClassLong32A( hwnd
, offset
, (LONG
)newval
);
707 case GCW_HBRBACKGROUND
: ptr
= &wndPtr
->class->hbrBackground
; break;
708 case GCW_HCURSOR
: ptr
= &wndPtr
->class->hCursor
; break;
709 case GCW_HICON
: ptr
= &wndPtr
->class->hIcon
; break;
710 case GCW_HICONSM
: ptr
= &wndPtr
->class->hIconSm
; break;
711 case GCW_ATOM
: ptr
= &wndPtr
->class->atomName
; break;
713 fprintf( stderr
, "Warning: invalid offset %d for SetClassWord()\n",
717 retval
= GET_WORD(ptr
);
718 PUT_WORD( ptr
, newval
);
723 /***********************************************************************
724 * SetClassLong16 (USER.132)
726 LONG WINAPI
SetClassLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
734 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
735 retval
= (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_16
);
736 WINPROC_SetProc( &wndPtr
->class->winproc
, (WNDPROC16
)newval
,
737 WIN_PROC_16
, WIN_PROC_CLASS
);
740 return SetClassLong32A( hwnd
, offset
, (LONG
)PTR_SEG_TO_LIN(newval
) );
742 return SetClassLong32A( hwnd
, offset
, newval
);
747 /***********************************************************************
748 * SetClassLong32A (USER32.467)
750 LONG WINAPI
SetClassLong32A( HWND32 hwnd
, INT32 offset
, LONG newval
)
756 if (!(wndPtr
= WIN_FindWndPtr( hwnd
))) return 0;
759 if (offset
+ sizeof(LONG
) <= wndPtr
->class->cbClsExtra
)
760 ptr
= ((char *)wndPtr
->class->wExtra
) + offset
;
763 fprintf( stderr
, "Warning: invalid offset %d for SetClassLong()\n",
771 CLASS_SetMenuNameA( wndPtr
->class, (LPCSTR
)newval
);
772 return 0; /* Old value is now meaningless anyway */
774 retval
= (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
,
776 WINPROC_SetProc( &wndPtr
->class->winproc
, (WNDPROC16
)newval
,
777 WIN_PROC_32A
, WIN_PROC_CLASS
);
779 case GCL_HBRBACKGROUND
:
783 return SetClassWord32( hwnd
, offset
, (WORD
)newval
);
784 case GCL_STYLE
: ptr
= &wndPtr
->class->style
; break;
785 case GCL_CBWNDEXTRA
: ptr
= &wndPtr
->class->cbWndExtra
; break;
786 case GCL_CBCLSEXTRA
: ptr
= &wndPtr
->class->cbClsExtra
; break;
787 case GCL_HMODULE
: ptr
= &wndPtr
->class->hInstance
; break;
789 fprintf( stderr
, "Warning: invalid offset %d for SetClassLong()\n",
793 retval
= GET_DWORD(ptr
);
794 PUT_DWORD( ptr
, newval
);
799 /***********************************************************************
800 * SetClassLong32W (USER32.468)
802 LONG WINAPI
SetClassLong32W( HWND32 hwnd
, INT32 offset
, LONG newval
)
810 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
811 retval
= (LONG
)WINPROC_GetProc( wndPtr
->class->winproc
, WIN_PROC_32W
);
812 WINPROC_SetProc( &wndPtr
->class->winproc
, (WNDPROC16
)newval
,
813 WIN_PROC_32W
, WIN_PROC_CLASS
);
816 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
817 CLASS_SetMenuNameW( wndPtr
->class, (LPCWSTR
)newval
);
818 return 0; /* Old value is now meaningless anyway */
820 return SetClassLong32A( hwnd
, offset
, newval
);
825 /***********************************************************************
826 * GetClassName16 (USER.58)
828 INT16 WINAPI
GetClassName16( HWND16 hwnd
, LPSTR buffer
, INT16 count
)
831 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
832 return GlobalGetAtomName16( wndPtr
->class->atomName
, buffer
, count
);
836 /***********************************************************************
837 * GetClassName32A (USER32.217)
839 INT32 WINAPI
GetClassName32A( HWND32 hwnd
, LPSTR buffer
, INT32 count
)
842 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
843 return GlobalGetAtomName32A( wndPtr
->class->atomName
, buffer
, count
);
847 /***********************************************************************
848 * GetClassName32W (USER32.218)
850 INT32 WINAPI
GetClassName32W( HWND32 hwnd
, LPWSTR buffer
, INT32 count
)
853 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return 0;
854 return GlobalGetAtomName32W( wndPtr
->class->atomName
, buffer
, count
);
858 /***********************************************************************
859 * GetClassInfo16 (USER.404)
861 BOOL16 WINAPI
GetClassInfo16( HINSTANCE16 hInstance
, SEGPTR name
,
867 hInstance
= GetExePtr( hInstance
);
868 if (!(atom
= GlobalFindAtom16( name
)) ||
869 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
871 if ((hInstance
!= classPtr
->hInstance
) &&
872 !(classPtr
->style
& CS_GLOBALCLASS
)) /*BWCC likes to pass hInstance=0*/
874 wc
->style
= (UINT16
)classPtr
->style
;
875 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, WIN_PROC_16
);
876 wc
->cbClsExtra
= (INT16
)classPtr
->cbClsExtra
;
877 wc
->cbWndExtra
= (INT16
)classPtr
->cbWndExtra
;
878 wc
->hInstance
= (HINSTANCE16
)classPtr
->hInstance
;
879 wc
->hIcon
= classPtr
->hIcon
;
880 wc
->hCursor
= classPtr
->hCursor
;
881 wc
->hbrBackground
= classPtr
->hbrBackground
;
882 wc
->lpszClassName
= (SEGPTR
)0;
883 wc
->lpszMenuName
= (SEGPTR
)CLASS_GetMenuNameA( classPtr
);
884 if (HIWORD(wc
->lpszMenuName
)) /* Make it a SEGPTR */
885 wc
->lpszMenuName
= SEGPTR_GET( (LPSTR
)wc
->lpszMenuName
);
890 /***********************************************************************
891 * GetClassInfo32A (USER32.211)
893 BOOL32 WINAPI
GetClassInfo32A( HINSTANCE32 hInstance
, LPCSTR name
,
899 if (!(atom
= GlobalFindAtom32A( name
)) ||
900 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
901 (classPtr
->hInstance
&& (hInstance
!= classPtr
->hInstance
)))
904 wc
->style
= classPtr
->style
;
905 wc
->lpfnWndProc
= (WNDPROC32
)WINPROC_GetProc( classPtr
->winproc
,
907 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
908 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
909 wc
->hInstance
= classPtr
->hInstance
;
910 wc
->hIcon
= (HICON32
)classPtr
->hIcon
;
911 wc
->hCursor
= (HCURSOR32
)classPtr
->hCursor
;
912 wc
->hbrBackground
= (HBRUSH32
)classPtr
->hbrBackground
;
913 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
914 wc
->lpszClassName
= NULL
;
919 /***********************************************************************
920 * GetClassInfo32W (USER32.214)
922 BOOL32 WINAPI
GetClassInfo32W( HINSTANCE32 hInstance
, LPCWSTR name
,
928 if (!(atom
= GlobalFindAtom32W( name
)) ||
929 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
930 (classPtr
->hInstance
&& (hInstance
!= classPtr
->hInstance
)))
933 wc
->style
= classPtr
->style
;
934 wc
->lpfnWndProc
= (WNDPROC32
)WINPROC_GetProc( classPtr
->winproc
,
936 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
937 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
938 wc
->hInstance
= classPtr
->hInstance
;
939 wc
->hIcon
= (HICON32
)classPtr
->hIcon
;
940 wc
->hCursor
= (HCURSOR32
)classPtr
->hCursor
;
941 wc
->hbrBackground
= (HBRUSH32
)classPtr
->hbrBackground
;
942 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
943 wc
->lpszClassName
= NULL
;
948 /***********************************************************************
949 * GetClassInfoEx16 (USER.398)
951 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
952 * same in Win16 as in Win32. --AJ
954 BOOL16 WINAPI
GetClassInfoEx16( HINSTANCE16 hInstance
, SEGPTR name
,
960 hInstance
= GetExePtr( hInstance
);
961 if (!(atom
= GlobalFindAtom16( name
)) ||
962 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
963 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
964 wc
->style
= classPtr
->style
;
965 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, WIN_PROC_16
);
966 wc
->cbClsExtra
= (INT16
)classPtr
->cbClsExtra
;
967 wc
->cbWndExtra
= (INT16
)classPtr
->cbWndExtra
;
968 wc
->hInstance
= (HINSTANCE16
)classPtr
->hInstance
;
969 wc
->hIcon
= classPtr
->hIcon
;
970 wc
->hIconSm
= classPtr
->hIconSm
;
971 wc
->hCursor
= classPtr
->hCursor
;
972 wc
->hbrBackground
= classPtr
->hbrBackground
;
973 wc
->lpszClassName
= (SEGPTR
)0;
974 wc
->lpszMenuName
= (SEGPTR
)CLASS_GetMenuNameA( classPtr
);
975 if (HIWORD(wc
->lpszMenuName
)) /* Make it a SEGPTR */
976 wc
->lpszMenuName
= SEGPTR_GET( (LPSTR
)wc
->lpszMenuName
);
981 /***********************************************************************
982 * GetClassInfoEx32A (USER32.212)
984 BOOL32 WINAPI
GetClassInfoEx32A( HINSTANCE32 hInstance
, LPCSTR name
,
990 if (!(atom
= GlobalFindAtom32A( name
)) ||
991 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
992 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
993 wc
->style
= classPtr
->style
;
994 wc
->lpfnWndProc
= (WNDPROC32
)WINPROC_GetProc( classPtr
->winproc
,
996 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
997 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
998 wc
->hInstance
= classPtr
->hInstance
;
999 wc
->hIcon
= (HICON32
)classPtr
->hIcon
;
1000 wc
->hIconSm
= (HICON32
)classPtr
->hIconSm
;
1001 wc
->hCursor
= (HCURSOR32
)classPtr
->hCursor
;
1002 wc
->hbrBackground
= (HBRUSH32
)classPtr
->hbrBackground
;
1003 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1004 wc
->lpszClassName
= NULL
;
1009 /***********************************************************************
1010 * GetClassInfoEx32W (USER32.213)
1012 BOOL32 WINAPI
GetClassInfoEx32W( HINSTANCE32 hInstance
, LPCWSTR name
,
1018 if (!(atom
= GlobalFindAtom32W( name
)) ||
1019 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
1020 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
1021 wc
->style
= classPtr
->style
;
1022 wc
->lpfnWndProc
= (WNDPROC32
)WINPROC_GetProc( classPtr
->winproc
,
1024 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1025 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1026 wc
->hInstance
= classPtr
->hInstance
;
1027 wc
->hIcon
= (HICON32
)classPtr
->hIcon
;
1028 wc
->hIconSm
= (HICON32
)classPtr
->hIconSm
;
1029 wc
->hCursor
= (HCURSOR32
)classPtr
->hCursor
;
1030 wc
->hbrBackground
= (HBRUSH32
)classPtr
->hbrBackground
;
1031 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1032 wc
->lpszClassName
= NULL
;
1037 /***********************************************************************
1038 * ClassFirst (TOOLHELP.69)
1040 BOOL16 WINAPI
ClassFirst( CLASSENTRY
*pClassEntry
)
1042 pClassEntry
->wNext
= 1;
1043 return ClassNext( pClassEntry
);
1047 /***********************************************************************
1048 * ClassNext (TOOLHELP.70)
1050 BOOL16 WINAPI
ClassNext( CLASSENTRY
*pClassEntry
)
1053 CLASS
*class = firstClass
;
1055 if (!pClassEntry
->wNext
) return FALSE
;
1056 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1059 pClassEntry
->wNext
= 0;
1062 pClassEntry
->hInst
= class->hInstance
;
1063 pClassEntry
->wNext
++;
1064 GlobalGetAtomName32A( class->atomName
, pClassEntry
->szClassName
,
1065 sizeof(pClassEntry
->szClassName
) );