class.c
来自「一个类似windows」· C语言 代码 · 共 2,236 行 · 第 1/5 页
C
2,236 行
else
lpwcx->lpszMenuName = Class->MenuName;
lpwcx->lpszClassName = (LPCWSTR)((ULONG_PTR)Class->Atom); /* FIXME - return the string? */
lpwcx->hIconSm = Class->hIconSm; /* FIXME - get handle from pointer */
return TRUE;
}
/* SYSCALLS *****************************************************************/
RTL_ATOM NTAPI
NtUserRegisterClassEx(IN CONST WNDCLASSEXW* lpwcx,
IN PUNICODE_STRING ClassName,
IN PUNICODE_STRING MenuName,
IN WNDPROC wpExtra,
IN DWORD Flags,
IN HMENU hMenu)
/*
* FUNCTION:
* Registers a new class with the window manager
* ARGUMENTS:
* lpwcx = Win32 extended window class structure
* bUnicodeClass = Whether to send ANSI or unicode strings
* to window procedures
* wpExtra = Extra window procedure, if this is not null, its used for the second window procedure for standard controls.
* RETURNS:
* Atom identifying the new class
*/
{
WNDCLASSEXW CapturedClassInfo = {0};
UNICODE_STRING CapturedName = {0}, CapturedMenuName = {0};
RTL_ATOM Ret = (RTL_ATOM)0;
if (Flags & ~REGISTERCLASS_ALL)
{
SetLastWin32Error(ERROR_INVALID_FLAGS);
return Ret;
}
UserEnterExclusive();
_SEH_TRY
{
/* Probe the parameters and basic parameter checks */
if (ProbeForReadUint(&lpwcx->cbSize) != sizeof(WNDCLASSEXW))
{
goto InvalidParameter;
}
ProbeForRead(lpwcx,
sizeof(WNDCLASSEXW),
sizeof(ULONG));
RtlCopyMemory(&CapturedClassInfo,
lpwcx,
sizeof(WNDCLASSEXW));
CapturedName = ProbeForReadUnicodeString(ClassName);
CapturedMenuName = ProbeForReadUnicodeString(MenuName);
if (CapturedName.Length & 1 || CapturedMenuName.Length & 1 ||
CapturedClassInfo.cbClsExtra < 0 ||
CapturedClassInfo.cbClsExtra + CapturedName.Length +
CapturedMenuName.Length + sizeof(WINDOWCLASS) < CapturedClassInfo.cbClsExtra ||
CapturedClassInfo.cbWndExtra < 0 ||
CapturedClassInfo.hInstance == NULL)
{
goto InvalidParameter;
}
if (CapturedName.Length != 0)
{
ProbeForRead(CapturedName.Buffer,
CapturedName.Length,
sizeof(WCHAR));
}
else
{
if (!IS_ATOM(CapturedName.Buffer))
{
goto InvalidParameter;
}
}
if (CapturedMenuName.Length != 0)
{
ProbeForRead(CapturedMenuName.Buffer,
CapturedMenuName.Length,
sizeof(WCHAR));
}
else if (CapturedMenuName.Buffer != NULL &&
!IS_INTRESOURCE(CapturedMenuName.Buffer))
{
InvalidParameter:
SetLastWin32Error(ERROR_INVALID_PARAMETER);
_SEH_LEAVE;
}
/* Register the class */
Ret = UserRegisterClass(&CapturedClassInfo,
&CapturedName,
&CapturedMenuName,
hMenu, /* FIXME - pass pointer */
wpExtra,
Flags);
}
_SEH_HANDLE
{
SetLastNtError(_SEH_GetExceptionCode());
}
_SEH_END;
UserLeave();
return Ret;
}
ULONG_PTR NTAPI
NtUserGetClassLong(IN HWND hWnd,
IN INT Offset,
IN BOOL Ansi)
{
PWINDOW_OBJECT Window;
ULONG_PTR Ret = 0;
if (Offset != GCLP_WNDPROC)
{
UserEnterShared();
}
else
{
UserEnterExclusive();
}
Window = UserGetWindowObject(hWnd);
if (Window != NULL)
{
Ret = UserGetClassLongPtr(Window->Class,
Offset,
Ansi);
if (Ret != 0 && Offset == GCLP_MENUNAME && !IS_INTRESOURCE(Ret))
{
Ret = (ULONG_PTR)DesktopHeapAddressToUser(Window->Class->Desktop,
(PVOID)Ret);
}
}
UserLeave();
return Ret;
}
ULONG_PTR STDCALL
NtUserSetClassLong(HWND hWnd,
INT Offset,
ULONG_PTR dwNewLong,
BOOL Ansi)
{
PW32PROCESSINFO pi;
PWINDOW_OBJECT Window;
ULONG_PTR Ret = 0;
UserEnterExclusive();
pi = GetW32ProcessInfo();
if (pi == NULL)
goto Cleanup;
Window = UserGetWindowObject(hWnd);
if (Window != NULL)
{
if (Window->ti->kpi != pi)
{
SetLastWin32Error(ERROR_ACCESS_DENIED);
goto Cleanup;
}
_SEH_TRY
{
UNICODE_STRING Value;
/* probe the parameters */
if (Offset == GCW_ATOM || Offset == GCLP_MENUNAME)
{
Value = ProbeForReadUnicodeString((PUNICODE_STRING)dwNewLong);
if (Value.Length & 1)
{
goto InvalidParameter;
}
if (Value.Length != 0)
{
ProbeForRead(Value.Buffer,
Value.Length,
sizeof(WCHAR));
}
else
{
if (Offset == GCW_ATOM && !IS_ATOM(Value.Buffer))
{
goto InvalidParameter;
}
else if (Offset == GCLP_MENUNAME && !IS_INTRESOURCE(Value.Buffer))
{
InvalidParameter:
SetLastWin32Error(ERROR_INVALID_PARAMETER);
_SEH_LEAVE;
}
}
dwNewLong = (ULONG_PTR)&Value;
}
Ret = UserSetClassLongPtr(Window->Class,
Offset,
dwNewLong,
Ansi);
}
_SEH_HANDLE
{
SetLastNtError(_SEH_GetExceptionCode());
}
_SEH_END;
}
Cleanup:
UserLeave();
return Ret;
}
DWORD STDCALL
NtUserSetClassWord(DWORD Unknown0,
DWORD Unknown1,
DWORD Unknown2)
{
return(0);
}
BOOL NTAPI
NtUserUnregisterClass(IN PUNICODE_STRING ClassNameOrAtom,
IN HINSTANCE hInstance)
{
UNICODE_STRING CapturedClassName;
BOOL Ret = FALSE;
UserEnterExclusive();
_SEH_TRY
{
/* probe the paramters */
CapturedClassName = ProbeForReadUnicodeString(ClassNameOrAtom);
if (CapturedClassName.Length & 1)
{
goto InvalidParameter;
}
if (CapturedClassName.Length != 0)
{
ProbeForRead(CapturedClassName.Buffer,
CapturedClassName.Length,
sizeof(WCHAR));
}
else
{
if (!IS_ATOM(CapturedClassName.Buffer))
{
InvalidParameter:
SetLastWin32Error(ERROR_INVALID_PARAMETER);
_SEH_LEAVE;
}
}
/* unregister the class */
Ret = UserUnregisterClass(&CapturedClassName,
hInstance);
}
_SEH_HANDLE
{
SetLastNtError(_SEH_GetExceptionCode());
}
_SEH_END;
UserLeave();
return Ret;
}
/* NOTE: for system classes hInstance is not NULL here, but User32Instance */
BOOL STDCALL
NtUserGetClassInfo(
HINSTANCE hInstance,
PUNICODE_STRING ClassName,
LPWNDCLASSEXW lpWndClassEx,
BOOL Ansi)
{
UNICODE_STRING CapturedClassName;
PWINDOWCLASS Class;
RTL_ATOM ClassAtom;
PW32PROCESSINFO pi;
BOOL Ret = FALSE;
/* NOTE: need exclusive lock because getting the wndproc might require the
creation of a call procedure handle */
UserEnterExclusive();
pi = GetW32ProcessInfo();
if (pi == NULL)
{
goto Cleanup;
}
_SEH_TRY
{
/* probe the paramters */
CapturedClassName = ProbeForReadUnicodeString(ClassName);
if (CapturedClassName.Length & 1)
{
goto InvalidParameter;
}
if (CapturedClassName.Length != 0)
{
ProbeForRead(CapturedClassName.Buffer,
CapturedClassName.Length,
sizeof(WCHAR));
}
else
{
if (!IS_ATOM(CapturedClassName.Buffer))
{
goto InvalidParameter;
}
}
if (ProbeForReadUint(&lpWndClassEx->cbSize) != sizeof(WNDCLASSEXW))
{
InvalidParameter:
SetLastWin32Error(ERROR_INVALID_PARAMETER);
_SEH_LEAVE;
}
ProbeForWrite(lpWndClassEx,
sizeof(WNDCLASSEXW),
sizeof(ULONG));
ClassAtom = IntGetClassAtom(&CapturedClassName,
hInstance,
pi,
&Class,
NULL);
if (ClassAtom != (RTL_ATOM)0)
{
Ret = UserGetClassInfo(Class,
lpWndClassEx,
Ansi);
if (Ret)
{
lpWndClassEx->lpszClassName = CapturedClassName.Buffer;
/* FIXME - handle Class->Desktop == NULL!!!!! */
if (Class->MenuName != NULL &&
!IS_INTRESOURCE(Class->MenuName))
{
lpWndClassEx->lpszMenuName = DesktopHeapAddressToUser(Class->Desktop,
(Ansi ?
(PVOID)Class->AnsiMenuName :
(PVOID)Class->MenuName));
}
}
}
}
_SEH_HANDLE
{
SetLastNtError(_SEH_GetExceptionCode());
}
_SEH_END;
Cleanup:
UserLeave();
return Ret;
}
INT NTAPI
NtUserGetClassName (IN HWND hWnd,
OUT PUNICODE_STRING ClassName,
IN BOOL Ansi)
{
PWINDOW_OBJECT Window;
UNICODE_STRING CapturedClassName;
INT Ret = 0;
UserEnterShared();
Window = UserGetWindowObject(hWnd);
if (Window != NULL)
{
_SEH_TRY
{
ProbeForWriteUnicodeString(ClassName);
CapturedClassName = *ClassName;
/* get the class name */
Ret = UserGetClassName(Window->Class,
&CapturedClassName,
Ansi);
if (Ret != 0)
{
/* update the Length field */
ClassName->Length = CapturedClassName.Length;
}
}
_SEH_HANDLE
{
SetLastNtError(_SEH_GetExceptionCode());
}
_SEH_END;
}
UserLeave();
return Ret;
}
DWORD STDCALL
NtUserGetWOWClass(DWORD Unknown0,
DWORD Unknown1)
{
return(0);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?