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.21 2003/08/04 16:54:54 gdalsnes 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 ClassReferenceClassByAtom(PWNDCLASS_OBJECT
* Class
,
63 PWNDCLASS_OBJECT Current
;
64 PLIST_ENTRY CurrentEntry
;
65 PW32PROCESS Process
= PsGetWin32Process();
67 ExAcquireFastMutexUnsafe (&Process
->ClassListLock
);
68 CurrentEntry
= Process
->ClassListHead
.Flink
;
69 while (CurrentEntry
!= &Process
->ClassListHead
)
71 Current
= CONTAINING_RECORD(CurrentEntry
, WNDCLASS_OBJECT
, ListEntry
);
73 if (Current
->Class
.lpszClassName
== (LPWSTR
)(ULONG
)Atom
)
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 ClassReferenceClassByName(PWNDCLASS_OBJECT
*Class
,
92 PWINSTATION_OBJECT WinStaObject
;
98 return(STATUS_INVALID_PARAMETER
);
101 Status
= ValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
105 if (!NT_SUCCESS(Status
))
107 DPRINT("Validation of window station handle (0x%X) failed\n",
108 PROCESS_WINDOW_STATION());
109 return(STATUS_UNSUCCESSFUL
);
112 Status
= RtlLookupAtomInAtomTable(WinStaObject
->AtomTable
,
116 if (!NT_SUCCESS(Status
))
118 ObDereferenceObject(WinStaObject
);
121 Status
= ClassReferenceClassByAtom(Class
,
124 ObDereferenceObject(WinStaObject
);
129 ClassReferenceClassByNameOrAtom(PWNDCLASS_OBJECT
*Class
,
130 LPWSTR ClassNameOrAtom
)
134 if (IS_ATOM(ClassNameOrAtom
))
136 Status
= ClassReferenceClassByAtom(Class
,
137 (RTL_ATOM
)((ULONG_PTR
)ClassNameOrAtom
));
141 Status
= ClassReferenceClassByName(Class
,
145 if (!NT_SUCCESS(Status
))
147 SetLastNtError(Status
);
154 NtUserGetClassInfo(IN LPWSTR ClassName
,
158 OUT PULONG ReturnedLength
)
166 NtUserGetClassName(DWORD Unknown0
,
176 NtUserGetWOWClass(DWORD Unknown0
,
184 PWNDCLASS_OBJECT FASTCALL
185 W32kCreateClass(LPWNDCLASSEXW lpwcx
,
189 PWNDCLASS_OBJECT ClassObject
;
193 objectSize
= sizeof(WNDCLASS_OBJECT
) +
194 (lpwcx
->lpszMenuName
!= 0 ? ((wcslen (lpwcx
->lpszMenuName
) + 1) * 2) : 0);
195 ClassObject
= ObmCreateObject(NULL
, NULL
, otClass
, objectSize
);
196 if (ClassObject
== 0)
201 ClassObject
->Class
= *lpwcx
;
202 ClassObject
->Unicode
= bUnicodeClass
;
203 if (lpwcx
->lpszMenuName
!= 0)
205 namePtr
= (LPTSTR
)(((PCHAR
)ClassObject
) + sizeof (WNDCLASS_OBJECT
));
206 ClassObject
->Class
.lpszMenuName
= namePtr
;
207 wcscpy (namePtr
, lpwcx
->lpszMenuName
);
209 ClassObject
->Class
.lpszClassName
= (LPWSTR
)(ULONG
)Atom
;
214 NtUserRegisterClassExWOW(LPWNDCLASSEXW lpwcx
,
222 * Registers a new class with the window manager
224 * lpcx = Win32 extended window class structure
225 * bUnicodeClass = Wether to send ANSI or unicode strings
226 * to window procedures
228 * Atom identifying the new class
231 PWINSTATION_OBJECT WinStaObject
;
232 PWNDCLASS_OBJECT ClassObject
;
236 DPRINT("About to open window station handle (0x%X)\n",
237 PROCESS_WINDOW_STATION());
239 Status
= ValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
243 if (!NT_SUCCESS(Status
))
245 DPRINT("Validation of window station handle (0x%X) failed\n",
246 PROCESS_WINDOW_STATION());
249 if (!IS_ATOM(lpwcx
->lpszClassName
))
251 Status
= RtlAddAtomToAtomTable(WinStaObject
->AtomTable
,
252 (LPWSTR
)lpwcx
->lpszClassName
,
254 if (!NT_SUCCESS(Status
))
256 ObDereferenceObject(WinStaObject
);
257 DPRINT("Failed adding class name (%wS) to atom table\n",
258 lpwcx
->lpszClassName
);
259 SetLastNtError(Status
);
265 Atom
= (RTL_ATOM
)(ULONG
)lpwcx
->lpszClassName
;
267 ClassObject
= W32kCreateClass(lpwcx
, bUnicodeClass
, Atom
);
268 if (ClassObject
== NULL
)
270 if (!IS_ATOM(lpwcx
->lpszClassName
))
272 RtlDeleteAtomFromAtomTable(WinStaObject
->AtomTable
, Atom
);
274 ObDereferenceObject(WinStaObject
);
275 DPRINT("Failed creating window class object\n");
276 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
279 ExAcquireFastMutex(&PsGetWin32Process()->ClassListLock
);
280 InsertTailList(&PsGetWin32Process()->ClassListHead
, &ClassObject
->ListEntry
);
281 ExReleaseFastMutex(&PsGetWin32Process()->ClassListLock
);
283 ObDereferenceObject(WinStaObject
);
289 W32kGetClassLong(PWINDOW_OBJECT WindowObject
, ULONG Offset
)
295 Ret
= WindowObject
->Class
->Class
.style
;
298 Ret
= WindowObject
->Class
->Class
.cbWndExtra
;
301 Ret
= WindowObject
->Class
->Class
.cbClsExtra
;
304 Ret
= (ULONG
)WindowObject
->Class
->Class
.hInstance
;
306 case GCL_HBRBACKGROUND
:
307 Ret
= (ULONG
)WindowObject
->Class
->Class
.hbrBackground
;
317 NtUserGetClassLong(HWND hWnd
, DWORD Offset
)
319 PWINDOW_OBJECT WindowObject
;
322 WindowObject
= W32kGetWindowObject(hWnd
);
323 if (WindowObject
== NULL
)
327 Ret
= W32kGetClassLong(WindowObject
, Offset
);
328 W32kReleaseWindowObject(WindowObject
);
333 NtUserSetClassLong(HWND hWnd
, int Index
, LONG NewValue
, DWORD unk
)
341 NtUserSetClassWord(DWORD Unknown0
,
351 NtUserUnregisterClass(DWORD Unknown0
,