2 * Window classes functions
4 * Copyright 1993 Alexandre Julliard
7 static char Copyright[] = "Copyright Alexandre Julliard, 1993";
14 static HCLASS firstClass = 0;
17 /***********************************************************************
18 * CLASS_FindClassByName
20 * Return a handle and a pointer to the class.
22 HCLASS CLASS_FindClassByName( char * name, CLASS **ptr )
24 HCLASS class = firstClass;
27 *ptr = (CLASS *) USER_HEAP_ADDR(class);
28 if (!strcasecmp( (*ptr)->wc.lpszClassName, name )) return class;
29 class = (*ptr)->hNext;
34 /***********************************************************************
37 * Return a pointer to the CLASS structure corresponding to a HCLASS.
39 CLASS * CLASS_FindClassPtr( HCLASS hclass )
43 if (!hclass) return NULL;
44 ptr = (CLASS *) USER_HEAP_ADDR( hclass );
45 if (ptr->wMagic != CLASS_MAGIC) return NULL;
50 /***********************************************************************
51 * RegisterClass (USER.57)
53 ATOM RegisterClass( LPWNDCLASS class )
59 printf( "RegisterClass: wndproc=%08x hinst=%d name='%s'\n",
60 class->lpfnWndProc, class->hInstance, class->lpszClassName );
63 handle = USER_HEAP_ALLOC( GMEM_MOVEABLE, sizeof(CLASS)+class->cbClsExtra );
64 if (!handle) return 0;
65 newClass = (CLASS *) USER_HEAP_ADDR( handle );
66 newClass->hNext = firstClass;
67 newClass->wMagic = CLASS_MAGIC;
68 newClass->atomName = handle; /* Should be an atom */
69 newClass->hDCE = 0; /* Should allocate a DCE if needed */
70 newClass->cWindows = 0;
71 newClass->wc = *class;
73 /* Class name should also be set to zero. For now we need the
74 * name because we don't have atoms.
76 newClass->wc.lpszClassName = (char *)malloc(strlen(class->lpszClassName)+1);
77 strcpy( newClass->wc.lpszClassName, class->lpszClassName );
79 if (class->cbClsExtra) memset( newClass->wExtra, 0, class->cbClsExtra );
82 return handle; /* Should be an atom */
86 /***********************************************************************
87 * UnregisterClass (USER.403)
89 BOOL UnregisterClass( LPSTR className, HANDLE instance )
91 HANDLE class, next, prevClass;
92 CLASS * classPtr, * prevClassPtr;
94 /* Check if we can remove this class */
95 class = CLASS_FindClassByName( className, &classPtr );
96 if (!class) return FALSE;
97 if ((classPtr->wc.hInstance != instance) || (classPtr->cWindows > 0))
100 /* Remove the class from the linked list */
101 if (firstClass == class) firstClass = classPtr->hNext;
104 for (prevClass = firstClass; prevClass; prevClass=prevClassPtr->hNext)
106 prevClassPtr = (CLASS *) USER_HEAP_ADDR(prevClass);
107 if (prevClassPtr->hNext == class) break;
111 printf( "ERROR: Class list corrupted\n" );
114 prevClassPtr->hNext = classPtr->hNext;
117 USER_HEAP_FREE( class );
122 /***********************************************************************
123 * GetClassWord (USER.129)
125 WORD GetClassWord( HWND hwnd, short offset )
127 return (WORD)GetClassLong( hwnd, offset );
131 /***********************************************************************
132 * SetClassWord (USER.130)
134 WORD SetClassWord( HWND hwnd, short offset, WORD newval )
140 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
141 if ((classPtr = CLASS_FindClassPtr( wndPtr->hClass )))
143 WORD * ptr = (WORD *)(((char *)classPtr->wExtra) + offset);
147 GlobalUnlock( hwnd );
152 /***********************************************************************
153 * GetClassLong (USER.131)
155 LONG GetClassLong( HWND hwnd, short offset )
161 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
162 if ((classPtr = CLASS_FindClassPtr( wndPtr->hClass )))
163 retval = *(LONG *)(((char *)classPtr->wExtra) + offset);
164 GlobalUnlock( hwnd );
169 /***********************************************************************
170 * SetClassLong (USER.132)
172 LONG SetClassLong( HWND hwnd, short offset, LONG newval )
178 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
179 if ((classPtr = CLASS_FindClassPtr( wndPtr->hClass )))
181 LONG * ptr = (LONG *)(((char *)classPtr->wExtra) + offset);
185 GlobalUnlock( hwnd );