diff --git a/reactos/dll/win32/user32/include/user32.h b/reactos/dll/win32/user32/include/user32.h index c39f1025590..e064f240df7 100644 --- a/reactos/dll/win32/user32/include/user32.h +++ b/reactos/dll/win32/user32/include/user32.h @@ -89,3 +89,5 @@ PCALLPROC FASTCALL ValidateCallProc(HANDLE hCallProc); PWINDOW FASTCALL ValidateHwnd(HWND hwnd); PWINDOW FASTCALL ValidateHwndOrDesk(HWND hwnd); PWINDOW FASTCALL GetThreadDesktopWnd(VOID); +PVOID FASTCALL ValidateHandleNoErr(HANDLE handle, UINT uType); +PWINDOW FASTCALL ValidateHwndNoErr(HWND hwnd); diff --git a/reactos/dll/win32/user32/misc/misc.c b/reactos/dll/win32/user32/misc/misc.c index 9d2d2c663c2..6803d0ef032 100644 --- a/reactos/dll/win32/user32/misc/misc.c +++ b/reactos/dll/win32/user32/misc/misc.c @@ -421,6 +421,35 @@ ValidateHandle(HANDLE handle, UINT uType) return ret; } +// +// Validate Handle and return the pointer to the object. +// +PVOID +FASTCALL +ValidateHandleNoErr(HANDLE handle, UINT uType) +{ + PVOID ret; + PUSER_HANDLE_ENTRY pEntry; + + ASSERT(uType <= VALIDATE_TYPE_MONITOR); + + pEntry = GetUser32Handle(handle); + + if (pEntry && uType == 0) + uType = pEntry->type; + +// Must have an entry and must be the same type! + if ( (!pEntry) || (pEntry->type != uType) || !pEntry->ptr ) + return NULL; + + if (g_ObjectHeapTypeShared[uType]) + ret = SharedPtrToUser(pEntry->ptr); + else + ret = DesktopPtrToUser(pEntry->ptr); + + return ret; +} + // // Validate a callproc handle and return the pointer to the object. // @@ -474,6 +503,45 @@ ValidateHwnd(HWND hwnd) return NULL; } +// +// Validate a window handle and return the pointer to the object. +// +PWINDOW +FASTCALL +ValidateHwndNoErr(HWND hwnd) +{ + PWINDOW Wnd; + PW32CLIENTINFO ClientInfo = GetWin32ClientInfo(); + ASSERT(ClientInfo != NULL); + + /* See if the window is cached */ + if (hwnd == ClientInfo->hWND) + return ClientInfo->pvWND; + + Wnd = ValidateHandleNoErr((HANDLE)hwnd, VALIDATE_TYPE_WIN); + if (Wnd != NULL) + { + /* FIXME: Check if handle table entry is marked as deleting and + return NULL in this case! */ + +#if 0 + return Wnd; +#else + /* HACK HACK HACK! This needs to be done until WINDOW_OBJECT is completely + superseded by the WINDOW structure. We *ASSUME* a pointer to the WINDOW + structure to be at the beginning of the WINDOW_OBJECT structure!!! + + !!! REMOVE AS SOON AS WINDOW_OBJECT NO LONGER EXISTS !!! + */ + + if (*((PVOID*)Wnd) != NULL) + return DesktopPtrToUser(*((PVOID*)Wnd)); +#endif + } + + return NULL; +} + PWINDOW FASTCALL GetThreadDesktopWnd(VOID) diff --git a/reactos/dll/win32/user32/windows/window.c b/reactos/dll/win32/user32/windows/window.c index 5d112308ee7..897843e501c 100644 --- a/reactos/dll/win32/user32/windows/window.c +++ b/reactos/dll/win32/user32/windows/window.c @@ -1201,8 +1201,14 @@ IsIconic(HWND hWnd) BOOL STDCALL IsWindow(HWND hWnd) { - DWORD WndProc = NtUserGetWindowLong(hWnd, GWL_WNDPROC, FALSE); - return (0 != WndProc || ERROR_INVALID_WINDOW_HANDLE != GetLastError()); + PWINDOW Wnd = ValidateHwndNoErr(hWnd); + if (Wnd != NULL) + { + /* FIXME: If window is being destroyed return FALSE! */ + return TRUE; + } + + return FALSE; } @@ -1212,7 +1218,12 @@ IsWindow(HWND hWnd) BOOL STDCALL IsWindowUnicode(HWND hWnd) { - return NtUserIsWindowUnicode(hWnd); + PWINDOW Wnd = ValidateHwnd(hWnd); + + if (Wnd != NULL) + return Wnd->Unicode; + + return FALSE; } diff --git a/reactos/include/reactos/win32k/ntuser.h b/reactos/include/reactos/win32k/ntuser.h index 43005bb3333..e985901c5c0 100644 --- a/reactos/include/reactos/win32k/ntuser.h +++ b/reactos/include/reactos/win32k/ntuser.h @@ -115,6 +115,8 @@ typedef struct _WINDOW PWINDOWCLASS Class; /* Window name. */ UNICODE_STRING WindowName; + + UINT Unicode : 1; } WINDOW, *PWINDOW; typedef struct _W32PROCESSINFO diff --git a/reactos/subsystems/win32/win32k/include/window.h b/reactos/subsystems/win32/win32k/include/window.h index a074b0cd96b..03812a004b2 100644 --- a/reactos/subsystems/win32/win32k/include/window.h +++ b/reactos/subsystems/win32/win32k/include/window.h @@ -78,7 +78,6 @@ typedef struct _WINDOW_OBJECT ULONG PropListItems; /* Scrollbar info */ PWINDOW_SCROLLINFO Scroll; - BOOL Unicode; WNDPROC WndProc; PETHREAD OwnerThread; HWND hWndLastPopup; /* handle to last active popup window (wine doesn't use pointer, for unk. reason)*/ diff --git a/reactos/subsystems/win32/win32k/ntuser/message.c b/reactos/subsystems/win32/win32k/ntuser/message.c index dc8e84356dd..56165a56b02 100644 --- a/reactos/subsystems/win32/win32k/ntuser/message.c +++ b/reactos/subsystems/win32/win32k/ntuser/message.c @@ -385,7 +385,7 @@ NtUserDispatchMessage(PNTUSERDISPATCHMESSAGEINFO UnsafeMsgInfo) } else { - MsgInfo.Ansi = !Window->Unicode; + MsgInfo.Ansi = !Window->Wnd->Unicode; MsgInfo.Proc = Window->WndProc; } } @@ -1390,7 +1390,7 @@ co_IntSendMessageTimeoutSingle(HWND hWnd, RETURN( FALSE); } - Result = (ULONG_PTR)co_IntCallWindowProc(Window->WndProc, !Window->Unicode, hWnd, Msg, wParam, + Result = (ULONG_PTR)co_IntCallWindowProc(Window->WndProc, !Window->Wnd->Unicode, hWnd, Msg, wParam, lParamPacked,lParamBufferSize); if(uResult) @@ -1566,7 +1566,7 @@ co_IntDoSendMessage(HWND hWnd, sizeof(BOOL)); if (! NT_SUCCESS(Status)) { - Info.Ansi = ! Window->Unicode; + Info.Ansi = ! Window->Wnd->Unicode; } if (Window->IsSystem) @@ -1575,7 +1575,7 @@ co_IntDoSendMessage(HWND hWnd, } else { - Info.Ansi = !Window->Unicode; + Info.Ansi = !Window->Wnd->Unicode; Info.Proc = Window->WndProc; } } diff --git a/reactos/subsystems/win32/win32k/ntuser/misc.c b/reactos/subsystems/win32/win32k/ntuser/misc.c index 8982f6e931c..5afc6d1bba4 100644 --- a/reactos/subsystems/win32/win32k/ntuser/misc.c +++ b/reactos/subsystems/win32/win32k/ntuser/misc.c @@ -283,7 +283,7 @@ NtUserCallOneParam( { RETURN( FALSE); } - Result = Window->Unicode; + Result = Window->Wnd->Unicode; RETURN( Result); } diff --git a/reactos/subsystems/win32/win32k/ntuser/window.c b/reactos/subsystems/win32/win32k/ntuser/window.c index f57144d1687..68951faa2e4 100644 --- a/reactos/subsystems/win32/win32k/ntuser/window.c +++ b/reactos/subsystems/win32/win32k/ntuser/window.c @@ -525,7 +525,7 @@ IntGetWindowProc(IN PWINDOW_OBJECT Window, } else { - if (!Ansi == Window->Unicode) + if (!Ansi == Wnd->Unicode) { return Window->WndProc; } @@ -541,12 +541,12 @@ IntGetWindowProc(IN PWINDOW_OBJECT Window, NewCallProc = UserFindCallProc(Wnd->Class, Window->WndProc, - Window->Unicode); + Wnd->Unicode); if (NewCallProc == NULL) { NewCallProc = CreateCallProc(Wnd->ti->Desktop, Window->WndProc, - Window->Unicode, + Wnd->Unicode, Wnd->ti->kpi); if (NewCallProc == NULL) { @@ -1649,13 +1649,13 @@ AllocErr: if (Wnd->Class->System) { /* NOTE: Always create a unicode window for system classes! */ - Window->Unicode = TRUE; + Wnd->Unicode = TRUE; Window->WndProc = Wnd->Class->WndProc; Window->WndProcExtra = Wnd->Class->WndProcExtra; } else { - Window->Unicode = Wnd->Class->Unicode; + Wnd->Unicode = Wnd->Class->Unicode; Window->WndProc = Wnd->Class->WndProc; Window->CallProc = NULL; } @@ -3614,7 +3614,7 @@ IntSetWindowProc(PWINDOW_OBJECT Window, } else { - if (!Ansi == Window->Unicode) + if (!Ansi == Wnd->Unicode) { Ret = Window->WndProc; } @@ -3622,12 +3622,12 @@ IntSetWindowProc(PWINDOW_OBJECT Window, { CallProc = UserFindCallProc(Wnd->Class, Window->WndProc, - Window->Unicode); + Wnd->Unicode); if (CallProc == NULL) { CallProc = CreateCallProc(NULL, Window->WndProc, - Window->Unicode, + Wnd->Unicode, Wnd->ti->kpi); if (CallProc == NULL) { @@ -3656,7 +3656,7 @@ IntSetWindowProc(PWINDOW_OBJECT Window, { Window->WndProc = Wnd->Class->WndProc; Window->WndProcExtra = Wnd->Class->WndProcExtra; - Window->Unicode = !Ansi; + Wnd->Unicode = !Ansi; return Ret; } } @@ -3665,7 +3665,7 @@ IntSetWindowProc(PWINDOW_OBJECT Window, /* update the window procedure */ Window->WndProc = NewWndProc; - Window->Unicode = !Ansi; + Wnd->Unicode = !Ansi; return Ret; }