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->cWindows = 0;
70 newClass->wc = *class;
72 if (newClass->wc.style & CS_CLASSDC)
73 newClass->hdc = CreateDC( "DISPLAY", NULL, NULL, NULL );
74 else newClass->hdc = 0;
76 /* Class name should also be set to zero. For now we need the
77 * name because we don't have atoms.
79 newClass->wc.lpszClassName = (char *)malloc(strlen(class->lpszClassName)+1);
80 strcpy( newClass->wc.lpszClassName, class->lpszClassName );
82 if (class->cbClsExtra) memset( newClass->wExtra, 0, class->cbClsExtra );
85 return handle; /* Should be an atom */
89 /***********************************************************************
90 * UnregisterClass (USER.403)
92 BOOL UnregisterClass( LPSTR className, HANDLE instance )
94 HANDLE class, next, prevClass;
95 CLASS * classPtr, * prevClassPtr;
97 /* Check if we can remove this class */
98 class = CLASS_FindClassByName( className, &classPtr );
99 if (!class) return FALSE;
100 if ((classPtr->wc.hInstance != instance) || (classPtr->cWindows > 0))
103 /* Remove the class from the linked list */
104 if (firstClass == class) firstClass = classPtr->hNext;
107 for (prevClass = firstClass; prevClass; prevClass=prevClassPtr->hNext)
109 prevClassPtr = (CLASS *) USER_HEAP_ADDR(prevClass);
110 if (prevClassPtr->hNext == class) break;
114 printf( "ERROR: Class list corrupted\n" );
117 prevClassPtr->hNext = classPtr->hNext;
120 /* Delete the class */
121 if (classPtr->hdc) DeleteDC( classPtr->hdc );
122 if (classPtr->wc.hbrBackground) DeleteObject( classPtr->wc.hbrBackground );
123 USER_HEAP_FREE( class );
128 /***********************************************************************
129 * GetClassWord (USER.129)
131 WORD GetClassWord( HWND hwnd, short offset )
133 return (WORD)GetClassLong( hwnd, offset );
137 /***********************************************************************
138 * SetClassWord (USER.130)
140 WORD SetClassWord( HWND hwnd, short offset, WORD newval )
144 WORD *ptr, retval = 0;
146 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
147 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
148 ptr = (WORD *)(((char *)classPtr->wExtra) + offset);
155 /***********************************************************************
156 * GetClassLong (USER.131)
158 LONG GetClassLong( HWND hwnd, short offset )
163 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
164 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
165 return *(LONG *)(((char *)classPtr->wExtra) + offset);
169 /***********************************************************************
170 * SetClassLong (USER.132)
172 LONG SetClassLong( HWND hwnd, short offset, LONG newval )
176 LONG *ptr, retval = 0;
178 if (!(wndPtr = WIN_FindWndPtr( hwnd ))) return 0;
179 if (!(classPtr = CLASS_FindClassPtr( wndPtr->hClass ))) return 0;
180 ptr = (LONG *)(((char *)classPtr->wExtra) + offset);