1 /* $Id: class.c,v 1.33 2003/08/19 01:03:41 weiden 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
35 if(!lpszClass
|| !lpwcx
)
37 SetLastError(ERROR_INVALID_PARAMETER
);
41 if(IS_ATOM(lpszClass
))
42 str
= (LPWSTR
)lpszClass
;
44 Status
= HEAP_strdupAtoW (&str
, lpszClass
, NULL
);
45 if ( !NT_SUCCESS (Status
) )
47 SetLastError (RtlNtStatusToDosError(Status
));
52 str2
.MaximumLength
= 255;
53 str2
.Buffer
= (PWSTR
)RtlAllocateHeap(RtlGetProcessHeap(), 0,
54 str2
.MaximumLength
* sizeof(WCHAR
));
57 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY
));
61 w
.lpszMenuName
= (LPCWSTR
)&str2
;
62 retval
= (BOOL
)NtUserGetClassInfo(hinst
, str
, &w
, TRUE
, 0);
65 RtlCopyMemory ( lpwcx
, &w
, sizeof(WNDCLASSEXW
) );
67 if (!IS_INTRESOURCE(w
.lpszMenuName
) && w
.lpszMenuName
)
69 lpwcx
->lpszMenuName
= heap_string_poolA (str2
.Buffer
, str2
.Length
);
71 RtlFreeHeap(RtlGetProcessHeap(), 0, str2
.Buffer
);
91 if(!lpszClass
|| !lpwcx
)
93 SetLastError(ERROR_INVALID_PARAMETER
);
97 if(IS_ATOM(lpszClass
))
98 str
= (LPWSTR
)lpszClass
;
100 str
= HEAP_strdupW (lpszClass
, wcslen(lpszClass
) );
103 str2
.MaximumLength
= 255;
104 str2
.Buffer
= (PWSTR
)RtlAllocateHeap(RtlGetProcessHeap(), 0,
105 str2
.MaximumLength
* sizeof(WCHAR
));
108 SetLastError (RtlNtStatusToDosError(STATUS_NO_MEMORY
));
112 w
.lpszMenuName
= (LPCWSTR
)&str2
;
113 retval
= (BOOL
)NtUserGetClassInfo(hinst
, str
, &w
, TRUE
, 0);
116 RtlCopyMemory ( lpwcx
, &w
, sizeof(WNDCLASSEXW
) );
118 if (!IS_INTRESOURCE(w
.lpszMenuName
) && w
.lpszMenuName
)
120 lpwcx
->lpszMenuName
= heap_string_poolW (str2
.Buffer
, str2
.Length
);
123 RtlFreeHeap(RtlGetProcessHeap(), 0, str2
.Buffer
);
136 LPWNDCLASSA lpWndClass
)
141 if(!lpClassName
|| !lpWndClass
)
143 SetLastError(ERROR_INVALID_PARAMETER
);
147 retval
= GetClassInfoExA(hInstance
,lpClassName
,&w
);
148 RtlCopyMemory (lpWndClass
,&w
.style
,sizeof(WNDCLASSA
));
160 LPWNDCLASSW lpWndClass
)
165 if(!lpClassName
|| !lpWndClass
)
167 SetLastError(ERROR_INVALID_PARAMETER
);
171 retval
= GetClassInfoExW(hInstance
,lpClassName
,&w
);
172 RtlCopyMemory (lpWndClass
,&w
.style
,sizeof(WNDCLASSW
));
181 GetClassLongA ( HWND hWnd
, int nIndex
)
185 if ( nIndex
!= GCL_MENUNAME
)
187 return NtUserGetClassLong ( hWnd
, nIndex
, TRUE
);
190 str
= (PUNICODE_STRING
)NtUserGetClassLong ( hWnd
, nIndex
, TRUE
);
191 if ( IS_INTRESOURCE(str
) )
197 return (DWORD
)heap_string_poolA ( str
->Buffer
, str
->Length
);
205 GetClassLongW ( HWND hWnd
, int nIndex
)
209 if ( nIndex
!= GCL_MENUNAME
)
211 return NtUserGetClassLong ( hWnd
, nIndex
, FALSE
);
214 str
= (PUNICODE_STRING
)NtUserGetClassLong(hWnd
, nIndex
, TRUE
);
215 if ( IS_INTRESOURCE(str
) )
221 return (DWORD
)heap_string_poolW ( str
->Buffer
, str
->Length
);
242 ClassNameW
= HEAP_alloc ( (nMaxCount
+1)*sizeof(WCHAR
) );
244 result
= NtUserGetClassName ( hWnd
, ClassNameW
, nMaxCount
);
246 Status
= HEAP_strcpyWtoA ( lpClassName
, ClassNameW
, result
);
248 HEAP_free ( ClassNameW
);
250 if ( !NT_SUCCESS(Status
) )
273 ClassNameW
= HEAP_alloc ( (nMaxCount
+1) * sizeof(WCHAR
) );
275 result
= NtUserGetClassName ( hWnd
, ClassNameW
, nMaxCount
);
277 RtlCopyMemory ( lpClassName
, ClassNameW
, result
);
279 HEAP_free ( ClassNameW
);
294 * NOTE: Obsoleted in 32-bit windows
307 GetWindowLongA ( HWND hWnd
, int nIndex
)
309 return NtUserGetWindowLong(hWnd
, nIndex
, TRUE
);
318 GetWindowLongW(HWND hWnd
, int nIndex
)
320 return NtUserGetWindowLong(hWnd
, nIndex
, FALSE
);
328 GetWindowWord(HWND hWnd
, int nIndex
)
330 return (WORD
)NtUserGetWindowLong(hWnd
, nIndex
, TRUE
);
338 SetWindowWord ( HWND hWnd
,int nIndex
,WORD wNewWord
)
340 return (WORD
)NtUserSetWindowLong ( hWnd
, nIndex
, (LONG
)wNewWord
, TRUE
);
353 /* FIXME: Implement correct functionality of RealGetWindowClass */
354 return GetClassNameW(hwnd
,pszType
,cchType
);
368 /* FIXME: Implement correct functionality of RealGetWindowClass */
369 return GetClassNameA(hwnd
,pszType
,cchType
);
377 RegisterClassA(CONST WNDCLASSA
*lpWndClass
)
384 RtlCopyMemory ( &Class
.style
, lpWndClass
, sizeof(WNDCLASSA
) );
386 Class
.cbSize
= sizeof(WNDCLASSEXA
);
387 Class
.hIconSm
= INVALID_HANDLE_VALUE
;
389 return RegisterClassExA ( &Class
);
396 RegisterClassExA(CONST WNDCLASSEXA
*lpwcx
)
399 WNDCLASSEXW wndclass
;
401 LPWSTR ClassName
= NULL
;
402 LPWSTR MenuName
= NULL
;
404 if ( !lpwcx
|| (lpwcx
->cbSize
!= sizeof(WNDCLASSEXA
)) )
407 if ( !lpwcx
->lpszClassName
)
410 RtlCopyMemory ( &wndclass
, lpwcx
, sizeof(WNDCLASSEXW
) );
412 if ( !IS_ATOM(lpwcx
->lpszClassName
) )
414 Status
= HEAP_strdupAtoW ( &ClassName
, (LPCSTR
)lpwcx
->lpszClassName
, NULL
);
415 if ( !NT_SUCCESS (Status
) )
417 SetLastError (RtlNtStatusToDosError(Status
));
420 wndclass
.lpszClassName
= ClassName
;
423 if ( !IS_INTRESOURCE(lpwcx
->lpszMenuName
) )
425 Status
= HEAP_strdupAtoW ( &MenuName
, (LPCSTR
)lpwcx
->lpszMenuName
, NULL
);
426 if ( !NT_SUCCESS (Status
) )
429 HEAP_free ( ClassName
);
430 SetLastError (RtlNtStatusToDosError(Status
));
433 wndclass
.lpszMenuName
= MenuName
;
436 Atom
= NtUserRegisterClassExWOW ( &wndclass
, FALSE
, 0, 0, 0 );
438 /* free strings if neccessary */
439 if ( MenuName
) HEAP_free ( MenuName
);
440 if ( ClassName
) HEAP_free ( ClassName
);
451 RegisterClassExW(CONST WNDCLASSEXW
*lpwcx
)
455 WNDCLASSEXW wndclass
;
456 LPWSTR ClassName
= NULL
;
457 LPWSTR MenuName
= NULL
;
459 if ( !lpwcx
|| (lpwcx
->cbSize
!= sizeof(WNDCLASSEXA
)) )
462 if ( !lpwcx
->lpszClassName
)
465 hHeap
= RtlGetProcessHeap();
466 RtlCopyMemory ( &wndclass
, lpwcx
, sizeof(WNDCLASSEXW
) );
468 /* copy strings if needed */
470 if ( !IS_ATOM(lpwcx
->lpszClassName
) )
472 ClassName
= HEAP_strdupW ( lpwcx
->lpszClassName
, lstrlenW(lpwcx
->lpszClassName
) );
475 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY
));
478 wndclass
.lpszClassName
= ClassName
;
481 if ( !IS_INTRESOURCE(lpwcx
->lpszMenuName
) )
483 MenuName
= HEAP_strdupW ( lpwcx
->lpszMenuName
, lstrlenW(lpwcx
->lpszMenuName
) );
487 HEAP_free ( MenuName
);
488 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY
));
491 wndclass
.lpszMenuName
= MenuName
;
494 Atom
= NtUserRegisterClassExWOW ( &wndclass
, TRUE
, 0, 0, 0 );
496 /* free strings if neccessary */
497 if ( MenuName
) HEAP_free ( MenuName
);
498 if ( ClassName
) HEAP_free ( ClassName
);
507 RegisterClassW(CONST WNDCLASSW
*lpWndClass
)
514 RtlCopyMemory ( &Class
.style
, lpWndClass
, sizeof(WNDCLASSW
) );
516 Class
.cbSize
= sizeof(WNDCLASSEXW
);
517 Class
.hIconSm
= INVALID_HANDLE_VALUE
;
519 return RegisterClassExW ( &Class
);
533 PUNICODE_STRING str2
;
535 if ( nIndex
!= GCL_MENUNAME
)
537 return NtUserSetClassLong ( hWnd
, nIndex
, dwNewLong
, TRUE
);
539 if ( IS_INTRESOURCE(dwNewLong
) )
541 str2
= (PUNICODE_STRING
)dwNewLong
;
545 RtlCreateUnicodeString ( str2
, (LPWSTR
)dwNewLong
);
548 str
= (PUNICODE_STRING
)NtUserSetClassLong(hWnd
, nIndex
, (DWORD
)str2
, TRUE
);
550 if ( !IS_INTRESOURCE(dwNewLong
) )
552 RtlFreeUnicodeString ( str2
);
554 if ( IS_INTRESOURCE(str
) )
560 return (DWORD
)heap_string_poolA ( str
->Buffer
, str
->Length
);
576 PUNICODE_STRING str2
;
578 if (nIndex
!= GCL_MENUNAME
)
580 return NtUserSetClassLong ( hWnd
, nIndex
, dwNewLong
, FALSE
);
582 if ( IS_INTRESOURCE(dwNewLong
) )
584 str2
= (PUNICODE_STRING
)dwNewLong
;
588 RtlCreateUnicodeStringFromAsciiz ( str2
,(LPSTR
)dwNewLong
);
591 str
= (PUNICODE_STRING
)NtUserSetClassLong(hWnd
, nIndex
, (DWORD
)str2
, TRUE
);
593 if ( !IS_INTRESOURCE(dwNewLong
) )
595 RtlFreeUnicodeString(str2
);
597 if ( IS_INTRESOURCE(str
) )
603 return (DWORD
)heap_string_poolW ( str
->Buffer
, str
->Length
);
618 * NOTE: Obsoleted in 32-bit windows
636 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, TRUE
);
650 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);