1 /* $Id: class.c,v 1.37 2003/08/20 01:05:10 silverblade Exp $
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
396 GetWindowLongA ( HWND hWnd
, int nIndex
)
398 return NtUserGetWindowLong(hWnd
, nIndex
, TRUE
);
407 GetWindowLongW(HWND hWnd
, int nIndex
)
409 return NtUserGetWindowLong(hWnd
, nIndex
, FALSE
);
417 GetWindowWord(HWND hWnd
, int nIndex
)
419 return (WORD
)NtUserGetWindowLong(hWnd
, nIndex
, TRUE
);
427 SetWindowWord ( HWND hWnd
,int nIndex
,WORD wNewWord
)
429 return (WORD
)NtUserSetWindowLong ( hWnd
, nIndex
, (LONG
)wNewWord
, TRUE
);
442 /* FIXME: Implement correct functionality of RealGetWindowClass */
443 return GetClassNameW(hwnd
,pszType
,cchType
);
457 /* FIXME: Implement correct functionality of RealGetWindowClass */
458 return GetClassNameA(hwnd
,pszType
,cchType
);
466 RegisterClassA(CONST WNDCLASSA
*lpWndClass
)
473 RtlCopyMemory ( &Class
.style
, lpWndClass
, sizeof(WNDCLASSA
) );
475 Class
.cbSize
= sizeof(WNDCLASSEXA
);
476 Class
.hIconSm
= INVALID_HANDLE_VALUE
;
478 return RegisterClassExA ( &Class
);
485 RegisterClassExA(CONST WNDCLASSEXA
*lpwcx
)
488 WNDCLASSEXW wndclass
;
490 LPWSTR ClassName
= NULL
;
491 LPWSTR MenuName
= NULL
;
493 if ( !lpwcx
|| (lpwcx
->cbSize
!= sizeof(WNDCLASSEXA
)) )
496 if ( !lpwcx
->lpszClassName
)
499 RtlCopyMemory ( &wndclass
, lpwcx
, sizeof(WNDCLASSEXW
) );
501 if ( !IS_ATOM(lpwcx
->lpszClassName
) )
503 Status
= HEAP_strdupAtoW ( &ClassName
, (LPCSTR
)lpwcx
->lpszClassName
, NULL
);
504 if ( !NT_SUCCESS (Status
) )
506 SetLastError (RtlNtStatusToDosError(Status
));
509 wndclass
.lpszClassName
= ClassName
;
512 if ( !IS_INTRESOURCE(lpwcx
->lpszMenuName
) )
514 Status
= HEAP_strdupAtoW ( &MenuName
, (LPCSTR
)lpwcx
->lpszMenuName
, NULL
);
515 if ( !NT_SUCCESS (Status
) )
518 HEAP_free ( ClassName
);
519 SetLastError (RtlNtStatusToDosError(Status
));
522 wndclass
.lpszMenuName
= MenuName
;
525 Atom
= NtUserRegisterClassExWOW ( &wndclass
, FALSE
, 0, 0, 0 );
527 /* free strings if neccessary */
528 if ( MenuName
) HEAP_free ( MenuName
);
529 if ( ClassName
) HEAP_free ( ClassName
);
540 RegisterClassExW(CONST WNDCLASSEXW
*lpwcx
)
544 WNDCLASSEXW wndclass
;
545 LPWSTR ClassName
= NULL
;
546 LPWSTR MenuName
= NULL
;
548 if ( !lpwcx
|| (lpwcx
->cbSize
!= sizeof(WNDCLASSEXA
)) )
551 if ( !lpwcx
->lpszClassName
)
554 hHeap
= RtlGetProcessHeap();
555 RtlCopyMemory ( &wndclass
, lpwcx
, sizeof(WNDCLASSEXW
) );
557 /* copy strings if needed */
559 if ( !IS_ATOM(lpwcx
->lpszClassName
) )
561 ClassName
= HEAP_strdupW ( lpwcx
->lpszClassName
, lstrlenW(lpwcx
->lpszClassName
) );
564 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY
));
567 wndclass
.lpszClassName
= ClassName
;
570 if ( !IS_INTRESOURCE(lpwcx
->lpszMenuName
) )
572 MenuName
= HEAP_strdupW ( lpwcx
->lpszMenuName
, lstrlenW(lpwcx
->lpszMenuName
) );
576 HEAP_free ( MenuName
);
577 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY
));
580 wndclass
.lpszMenuName
= MenuName
;
583 Atom
= NtUserRegisterClassExWOW ( &wndclass
, TRUE
, 0, 0, 0 );
585 /* free strings if neccessary */
586 if ( MenuName
) HEAP_free ( MenuName
);
587 if ( ClassName
) HEAP_free ( ClassName
);
596 RegisterClassW(CONST WNDCLASSW
*lpWndClass
)
603 RtlCopyMemory ( &Class
.style
, lpWndClass
, sizeof(WNDCLASSW
) );
605 Class
.cbSize
= sizeof(WNDCLASSEXW
);
606 Class
.hIconSm
= INVALID_HANDLE_VALUE
;
608 return RegisterClassExW ( &Class
);
622 PUNICODE_STRING str2
;
624 if ( nIndex
!= GCL_MENUNAME
)
626 return NtUserSetClassLong ( hWnd
, nIndex
, dwNewLong
, TRUE
);
628 if ( IS_INTRESOURCE(dwNewLong
) )
630 str2
= (PUNICODE_STRING
)dwNewLong
;
634 RtlCreateUnicodeString ( str2
, (LPWSTR
)dwNewLong
);
637 str
= (PUNICODE_STRING
)NtUserSetClassLong(hWnd
, nIndex
, (DWORD
)str2
, TRUE
);
639 if ( !IS_INTRESOURCE(dwNewLong
) )
641 RtlFreeUnicodeString ( str2
);
643 if ( IS_INTRESOURCE(str
) )
649 return (DWORD
)heap_string_poolA ( str
->Buffer
, str
->Length
);
665 PUNICODE_STRING str2
;
667 if (nIndex
!= GCL_MENUNAME
)
669 return NtUserSetClassLong ( hWnd
, nIndex
, dwNewLong
, FALSE
);
671 if ( IS_INTRESOURCE(dwNewLong
) )
673 str2
= (PUNICODE_STRING
)dwNewLong
;
677 RtlCreateUnicodeStringFromAsciiz ( str2
,(LPSTR
)dwNewLong
);
680 str
= (PUNICODE_STRING
)NtUserSetClassLong(hWnd
, nIndex
, (DWORD
)str2
, TRUE
);
682 if ( !IS_INTRESOURCE(dwNewLong
) )
684 RtlFreeUnicodeString(str2
);
686 if ( IS_INTRESOURCE(str
) )
692 return (DWORD
)heap_string_poolW ( str
->Buffer
, str
->Length
);
707 * NOTE: Obsoleted in 32-bit windows
725 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, TRUE
);
739 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);