2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: class.c,v 1.16 2003/05/18 17:16:17 ea Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * PURPOSE: Window classes
24 * FILE: subsys/win32k/ntuser/class.c
25 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
27 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
31 #include <ddk/ntddk.h>
32 #include <win32k/win32k.h>
33 #include <napi/win32.h>
34 #include <include/class.h>
35 #include <include/error.h>
36 #include <include/winsta.h>
37 #include <include/object.h>
38 #include <include/guicheck.h>
39 #include <include/window.h>
44 /* FUNCTIONS *****************************************************************/
49 return(STATUS_SUCCESS
);
53 CleanupClassImpl(VOID
)
55 return(STATUS_SUCCESS
);
60 ClassReferenceClassByName(PW32PROCESS Process
,
61 PWNDCLASS_OBJECT
* Class
,
64 PWNDCLASS_OBJECT Current
;
65 PLIST_ENTRY CurrentEntry
;
67 ExAcquireFastMutexUnsafe (&Process
->ClassListLock
);
68 CurrentEntry
= Process
->ClassListHead
.Flink
;
69 while (CurrentEntry
!= &Process
->ClassListHead
)
71 Current
= CONTAINING_RECORD(CurrentEntry
, WNDCLASS_OBJECT
, ListEntry
);
73 if (_wcsicmp(ClassName
, Current
->Class
.lpszClassName
) == 0)
76 ObmReferenceObject(Current
);
77 ExReleaseFastMutexUnsafe (&Process
->ClassListLock
);
78 return(STATUS_SUCCESS
);
81 CurrentEntry
= CurrentEntry
->Flink
;
83 ExReleaseFastMutexUnsafe (&Process
->ClassListLock
);
85 return(STATUS_NOT_FOUND
);
89 ClassReferenceClassByAtom(PWNDCLASS_OBJECT
*Class
,
92 PWINSTATION_OBJECT WinStaObject
;
93 ULONG ClassNameLength
;
99 return(STATUS_INVALID_PARAMETER
);
102 Status
= ValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
106 if (!NT_SUCCESS(Status
))
108 DPRINT("Validation of window station handle (0x%X) failed\n",
109 PROCESS_WINDOW_STATION());
110 return(STATUS_UNSUCCESSFUL
);
113 ClassNameLength
= sizeof(ClassName
);
114 Status
= RtlQueryAtomInAtomTable(WinStaObject
->AtomTable
,
121 Status
= ClassReferenceClassByName(PsGetWin32Process(),
125 ObDereferenceObject(WinStaObject
);
131 ClassReferenceClassByNameOrAtom(PWNDCLASS_OBJECT
*Class
,
132 LPWSTR ClassNameOrAtom
)
136 if (IS_ATOM(ClassNameOrAtom
))
138 Status
= ClassReferenceClassByAtom(Class
,
139 (RTL_ATOM
)((ULONG_PTR
)ClassNameOrAtom
));
143 Status
= ClassReferenceClassByName(PsGetWin32Process(), Class
,
147 if (!NT_SUCCESS(Status
))
149 SetLastNtError(Status
);
156 NtUserGetClassInfo(IN LPWSTR ClassName
,
160 OUT PULONG ReturnedLength
)
168 NtUserGetClassName(DWORD Unknown0
,
178 NtUserGetWOWClass(DWORD Unknown0
,
186 PWNDCLASS_OBJECT FASTCALL
187 W32kCreateClass(LPWNDCLASSEX lpwcx
,
190 PWNDCLASS_OBJECT ClassObject
;
194 objectSize
= sizeof(WNDCLASS_OBJECT
) +
195 (lpwcx
->lpszMenuName
!= 0 ? ((wcslen (lpwcx
->lpszMenuName
) + 1) * 2) : 0) +
196 ((wcslen (lpwcx
->lpszClassName
) + 1) * 2);
197 ClassObject
= ObmCreateObject(NULL
, NULL
, otClass
, objectSize
);
198 if (ClassObject
== 0)
203 ClassObject
->Class
= *lpwcx
;
204 ClassObject
->Unicode
= bUnicodeClass
;
205 namePtr
= (LPTSTR
)(((PCHAR
)ClassObject
) + sizeof (WNDCLASS_OBJECT
));
206 if (lpwcx
->lpszMenuName
!= 0)
208 ClassObject
->Class
.lpszMenuName
= namePtr
;
209 wcscpy (namePtr
, lpwcx
->lpszMenuName
);
210 namePtr
+= wcslen (lpwcx
->lpszMenuName
) + 1;
212 ClassObject
->Class
.lpszClassName
= namePtr
;
213 wcscpy (namePtr
, lpwcx
->lpszClassName
);
218 NtUserRegisterClassExWOW(LPWNDCLASSEX lpwcx
,
226 * Registers a new class with the window manager
228 * lpcx = Win32 extended window class structure
229 * bUnicodeClass = Wether to send ANSI or unicode strings
230 * to window procedures
232 * Atom identifying the new class
235 PWINSTATION_OBJECT WinStaObject
;
236 PWNDCLASS_OBJECT ClassObject
;
242 DPRINT("About to open window station handle (0x%X)\n",
243 PROCESS_WINDOW_STATION());
245 Status
= ValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
249 if (!NT_SUCCESS(Status
))
251 DPRINT("Validation of window station handle (0x%X) failed\n",
252 PROCESS_WINDOW_STATION());
256 Status
= RtlAddAtomToAtomTable(WinStaObject
->AtomTable
,
257 (LPWSTR
)lpwcx
->lpszClassName
,
259 if (!NT_SUCCESS(Status
))
261 ObDereferenceObject(WinStaObject
);
262 DPRINT("Failed adding class name (%wS) to atom table\n",
263 lpwcx
->lpszClassName
);
264 SetLastNtError(Status
);
268 ClassObject
= W32kCreateClass(lpwcx
, bUnicodeClass
);
269 if (ClassObject
== NULL
)
271 RtlDeleteAtomFromAtomTable(WinStaObject
->AtomTable
, Atom
);
272 ObDereferenceObject(WinStaObject
);
273 DPRINT("Failed creating window class object\n");
274 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
277 ExAcquireFastMutex(&PsGetWin32Process()->ClassListLock
);
278 InsertTailList(&PsGetWin32Process()->ClassListHead
, &ClassObject
->ListEntry
);
279 ExReleaseFastMutex(&PsGetWin32Process()->ClassListLock
);
281 ObDereferenceObject(WinStaObject
);
287 W32kGetClassLong(PWINDOW_OBJECT WindowObject
, ULONG Offset
)
293 Ret
= WindowObject
->Class
->Class
.style
;
296 Ret
= WindowObject
->Class
->Class
.cbWndExtra
;
299 Ret
= WindowObject
->Class
->Class
.cbClsExtra
;
302 Ret
= (ULONG
)WindowObject
->Class
->Class
.hInstance
;
304 case GCL_HBRBACKGROUND
:
305 Ret
= (ULONG
)WindowObject
->Class
->Class
.hbrBackground
;
315 NtUserGetClassLong(HWND hWnd
, DWORD Offset
)
317 PWINDOW_OBJECT WindowObject
;
320 WindowObject
= W32kGetWindowObject(hWnd
);
321 if (WindowObject
== NULL
)
325 Ret
= W32kGetClassLong(WindowObject
, Offset
);
326 W32kReleaseWindowObject(WindowObject
);
331 NtUserSetClassLong(DWORD Unknown0
,
342 NtUserSetClassWord(DWORD Unknown0
,
352 NtUserUnregisterClass(DWORD Unknown0
,