3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/windows/class.c
6 * PURPOSE: Window classes
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 09-05-2001 CSH Created
21 static WINBOOL GetClassInfoExCommon(
28 UNICODE_STRING str2, str3;
33 if ( !lpszClass || !lpwcx )
35 SetLastError(ERROR_INVALID_PARAMETER);
39 if(IS_ATOM(lpszClass))
40 str = (LPWSTR)lpszClass;
45 str = HEAP_strdupW ( lpszClass, wcslen(lpszClass) );
49 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY));
56 Status = HEAP_strdupAtoW(&str, (LPCSTR)lpszClass, NULL);
58 if (! NT_SUCCESS(Status))
60 SetLastError(RtlNtStatusToDosError(Status));
66 str2.Length = str3.Length = 0;
67 str2.MaximumLength = str3.MaximumLength = 255;
68 str2.Buffer = (PWSTR)HEAP_alloc ( str2.MaximumLength * sizeof(WCHAR) );
71 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY));
77 str3.Buffer = (PWSTR)HEAP_alloc ( str3.MaximumLength * sizeof(WCHAR) );
80 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY));
86 w.lpszMenuName = (LPCWSTR)&str2;
87 w.lpszClassName = (LPCWSTR)&str3;
88 retval = (BOOL)NtUserGetClassInfo(hInst, str, &w, TRUE, 0);
92 RtlCopyMemory ( lpwcx, &w, sizeof(WNDCLASSEXW) );
94 if ( !IS_INTRESOURCE(w.lpszMenuName) && w.lpszMenuName )
97 lpwcx->lpszMenuName = heap_string_poolW ( str2.Buffer, str2.Length );
99 (LPWNDCLASSEXA) lpwcx->lpszMenuName = heap_string_poolA ( str2.Buffer, str2.Length );
102 if ( !IS_ATOM(w.lpszClassName) && w.lpszClassName )
105 lpwcx->lpszClassName = heap_string_poolW ( str3.Buffer, str3.Length );
107 (LPWNDCLASSEXA) lpwcx->lpszClassName = heap_string_poolA ( str3.Buffer, str3.Length );
110 HEAP_free ( str2.Buffer );
111 HEAP_free ( str3.Buffer );
127 return GetClassInfoExCommon(hinst, (LPWSTR)lpszClass, (LPWNDCLASSEXW)lpwcx, FALSE);
141 return GetClassInfoExCommon(hinst, lpszClass, lpwcx, TRUE);
143 // AG: I've kept this here (commented out) in case of bugs with my
144 // own "common" routine (see above):
150 UNICODE_STRING str2, str3;
155 if ( !lpszClass || !lpwcx )
157 SetLastError(ERROR_INVALID_PARAMETER);
161 if(IS_ATOM(lpszClass))
162 str = (LPWSTR)lpszClass;
165 str = HEAP_strdupW ( lpszClass, wcslen(lpszClass) );
168 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY));
173 str2.Length = str3.Length = 0;
174 str2.MaximumLength = str3.MaximumLength = 255;
175 str2.Buffer = (PWSTR)HEAP_alloc ( str2.MaximumLength * sizeof(WCHAR) );
178 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY));
184 str3.Buffer = (PWSTR)HEAP_alloc ( str3.MaximumLength * sizeof(WCHAR) );
187 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY));
190 HEAP_free ( str2.Buffer );
194 w.lpszMenuName = (LPCWSTR)&str2;
195 w.lpszClassName = (LPCWSTR)&str3;
196 retval = (BOOL)NtUserGetClassInfo(hinst, str, &w, TRUE, 0);
199 RtlCopyMemory ( lpwcx, &w, sizeof(WNDCLASSEXW) );
201 if ( !IS_INTRESOURCE(w.lpszMenuName) && w.lpszMenuName )
203 lpwcx->lpszMenuName = heap_string_poolW ( str2.Buffer, str2.Length );
205 if ( !IS_ATOM(w.lpszClassName) && w.lpszClassName )
207 lpwcx->lpszClassName = heap_string_poolW ( str3.Buffer, str3.Length );
210 HEAP_free ( str2.Buffer );
211 HEAP_free ( str3.Buffer );
225 LPWNDCLASSA lpWndClass)
230 if ( !lpClassName || !lpWndClass )
232 SetLastError(ERROR_INVALID_PARAMETER);
236 retval = GetClassInfoExA(hInstance,lpClassName,&w);
237 RtlCopyMemory ( lpWndClass, &w.style, sizeof(WNDCLASSA) );
249 LPWNDCLASSW lpWndClass)
254 if(!lpClassName || !lpWndClass)
256 SetLastError(ERROR_INVALID_PARAMETER);
260 retval = GetClassInfoExW(hInstance,lpClassName,&w);
261 RtlCopyMemory (lpWndClass,&w.style,sizeof(WNDCLASSW));
270 GetClassLongA ( HWND hWnd, int nIndex )
274 if ( nIndex != GCL_MENUNAME )
276 return NtUserGetClassLong ( hWnd, nIndex, TRUE );
279 str = (PUNICODE_STRING)NtUserGetClassLong ( hWnd, nIndex, TRUE );
280 if ( IS_INTRESOURCE(str) )
286 return (DWORD)heap_string_poolA ( str->Buffer, str->Length );
294 GetClassLongW ( HWND hWnd, int nIndex )
298 if ( nIndex != GCL_MENUNAME )
300 return NtUserGetClassLong ( hWnd, nIndex, FALSE );
303 str = (PUNICODE_STRING)NtUserGetClassLong(hWnd, nIndex, TRUE);
304 if ( IS_INTRESOURCE(str) )
310 return (DWORD)heap_string_poolW ( str->Buffer, str->Length );
331 ClassNameW = HEAP_alloc ( (nMaxCount+1)*sizeof(WCHAR) );
333 result = NtUserGetClassName ( hWnd, ClassNameW, nMaxCount );
335 Status = HEAP_strcpyWtoA ( lpClassName, ClassNameW, result );
337 HEAP_free ( ClassNameW );
339 if ( !NT_SUCCESS(Status) )
362 ClassNameW = HEAP_alloc ( (nMaxCount+1) * sizeof(WCHAR) );
364 result = NtUserGetClassName ( hWnd, ClassNameW, nMaxCount );
366 RtlCopyMemory ( lpClassName, ClassNameW, result );
368 HEAP_free ( ClassNameW );
383 * NOTE: Obsoleted in 32-bit windows
386 if ((nIndex < 0) && (nIndex != GCW_ATOM))
389 return (WORD) NtUserGetClassLong ( hWnd, nIndex, TRUE );
398 GetWindowLongA ( HWND hWnd, int nIndex )
400 return NtUserGetWindowLong(hWnd, nIndex, TRUE);
409 GetWindowLongW(HWND hWnd, int nIndex)
411 return NtUserGetWindowLong(hWnd, nIndex, FALSE);
419 GetWindowWord(HWND hWnd, int nIndex)
421 return (WORD)NtUserGetWindowLong(hWnd, nIndex, TRUE);
429 SetWindowWord ( HWND hWnd,int nIndex,WORD wNewWord )
431 return (WORD)NtUserSetWindowLong ( hWnd, nIndex, (LONG)wNewWord, TRUE );
444 /* FIXME: Implement correct functionality of RealGetWindowClass */
445 return GetClassNameW(hwnd,pszType,cchType);
459 /* FIXME: Implement correct functionality of RealGetWindowClass */
460 return GetClassNameA(hwnd,pszType,cchType);
468 RegisterClassA(CONST WNDCLASSA *lpWndClass)
475 RtlCopyMemory ( &Class.style, lpWndClass, sizeof(WNDCLASSA) );
477 Class.cbSize = sizeof(WNDCLASSEXA);
478 Class.hIconSm = INVALID_HANDLE_VALUE;
480 return RegisterClassExA ( &Class );
487 RegisterClassExA(CONST WNDCLASSEXA *lpwcx)
490 WNDCLASSEXW wndclass;
492 LPWSTR ClassName = NULL;
493 LPWSTR MenuName = NULL;
495 if ( !lpwcx || (lpwcx->cbSize != sizeof(WNDCLASSEXA)) )
498 if ( !lpwcx->lpszClassName )
501 RtlCopyMemory ( &wndclass, lpwcx, sizeof(WNDCLASSEXW) );
503 if ( !IS_ATOM(lpwcx->lpszClassName) )
505 Status = HEAP_strdupAtoW ( &ClassName, (LPCSTR)lpwcx->lpszClassName, NULL );
506 if ( !NT_SUCCESS (Status) )
508 SetLastError (RtlNtStatusToDosError(Status));
511 wndclass.lpszClassName = ClassName;
514 if ( !IS_INTRESOURCE(lpwcx->lpszMenuName) )
516 Status = HEAP_strdupAtoW ( &MenuName, (LPCSTR)lpwcx->lpszMenuName, NULL );
517 if ( !NT_SUCCESS (Status) )
520 HEAP_free ( ClassName );
521 SetLastError (RtlNtStatusToDosError(Status));
524 wndclass.lpszMenuName = MenuName;
527 Atom = NtUserRegisterClassExWOW ( &wndclass, FALSE, 0, 0, 0 );
529 /* free strings if neccessary */
530 if ( MenuName ) HEAP_free ( MenuName );
531 if ( ClassName ) HEAP_free ( ClassName );
542 RegisterClassExW(CONST WNDCLASSEXW *lpwcx)
546 WNDCLASSEXW wndclass;
547 LPWSTR ClassName = NULL;
548 LPWSTR MenuName = NULL;
550 if ( !lpwcx || (lpwcx->cbSize != sizeof(WNDCLASSEXA)) )
553 if ( !lpwcx->lpszClassName )
556 hHeap = RtlGetProcessHeap();
557 RtlCopyMemory ( &wndclass, lpwcx, sizeof(WNDCLASSEXW) );
559 /* copy strings if needed */
561 if ( !IS_ATOM(lpwcx->lpszClassName) )
563 ClassName = HEAP_strdupW ( lpwcx->lpszClassName, lstrlenW(lpwcx->lpszClassName) );
566 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY));
569 wndclass.lpszClassName = ClassName;
572 if ( !IS_INTRESOURCE(lpwcx->lpszMenuName) )
574 MenuName = HEAP_strdupW ( lpwcx->lpszMenuName, lstrlenW(lpwcx->lpszMenuName) );
578 HEAP_free ( MenuName );
579 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY));
582 wndclass.lpszMenuName = MenuName;
585 Atom = NtUserRegisterClassExWOW ( &wndclass, TRUE, 0, 0, 0 );
587 /* free strings if neccessary */
588 if ( MenuName ) HEAP_free ( MenuName );
589 if ( ClassName ) HEAP_free ( ClassName );
598 RegisterClassW(CONST WNDCLASSW *lpWndClass)
605 RtlCopyMemory ( &Class.style, lpWndClass, sizeof(WNDCLASSW) );
607 Class.cbSize = sizeof(WNDCLASSEXW);
608 Class.hIconSm = INVALID_HANDLE_VALUE;
610 return RegisterClassExW ( &Class );
624 PUNICODE_STRING str2;
626 if ( nIndex != GCL_MENUNAME )
628 return NtUserSetClassLong ( hWnd, nIndex, dwNewLong, TRUE );
630 if ( IS_INTRESOURCE(dwNewLong) )
632 str2 = (PUNICODE_STRING)dwNewLong;
636 RtlCreateUnicodeString ( str2, (LPWSTR)dwNewLong );
639 str = (PUNICODE_STRING)NtUserSetClassLong(hWnd, nIndex, (DWORD)str2, TRUE);
641 if ( !IS_INTRESOURCE(dwNewLong) )
643 RtlFreeUnicodeString ( str2 );
645 if ( IS_INTRESOURCE(str) )
651 return (DWORD)heap_string_poolA ( str->Buffer, str->Length );
667 PUNICODE_STRING str2;
669 if (nIndex != GCL_MENUNAME )
671 return NtUserSetClassLong ( hWnd, nIndex, dwNewLong, FALSE );
673 if ( IS_INTRESOURCE(dwNewLong) )
675 str2 = (PUNICODE_STRING)dwNewLong;
679 RtlCreateUnicodeStringFromAsciiz ( str2,(LPSTR)dwNewLong );
682 str = (PUNICODE_STRING)NtUserSetClassLong(hWnd, nIndex, (DWORD)str2, TRUE);
684 if ( !IS_INTRESOURCE(dwNewLong) )
686 RtlFreeUnicodeString(str2);
688 if ( IS_INTRESOURCE(str) )
694 return (DWORD)heap_string_poolW ( str->Buffer, str->Length );
709 * NOTE: Obsoleted in 32-bit windows
712 if ((nIndex < 0) && (nIndex != GCW_ATOM))
715 return (WORD) NtUserSetClassLong ( hWnd, nIndex, wNewWord, TRUE );
729 return NtUserSetWindowLong(hWnd, nIndex, dwNewLong, TRUE);
743 return NtUserSetWindowLong(hWnd, nIndex, dwNewLong, FALSE);