return pi;
}
+static PDESKTOP
+GetThreadDesktopInfo(VOID)
+{
+ PW32THREADINFO ti;
+ PDESKTOP di = NULL;
+
+ ti = GetW32ThreadInfo();
+ if (ti != NULL)
+ di = DesktopPtrToUser(ti->Desktop);
+
+ return di;
+}
+
/*
* GetUserObjectSecurity
FASTCALL
ValidateHwnd(HWND hwnd)
{
+ PWINDOW Wnd;
PW32CLIENTINFO ClientInfo = GetWin32ClientInfo();
ASSERT(ClientInfo != NULL);
if (hwnd == ClientInfo->hWND)
return ClientInfo->pvWND;
- PWINDOW Wnd = ValidateHandle((HANDLE)hwnd, VALIDATE_TYPE_WIN);
+ Wnd = ValidateHandle((HANDLE)hwnd, VALIDATE_TYPE_WIN);
if (Wnd != NULL)
{
/* FIXME: Check if handle table entry is marked as deleting and
return NULL;
}
+
+PWINDOW
+FASTCALL
+GetThreadDesktopWnd(VOID)
+{
+ PWINDOW Wnd = GetThreadDesktopInfo()->Wnd;
+ if (Wnd != NULL)
+ Wnd = DesktopPtrToUser(Wnd);
+ return Wnd;
+}
+
+//
+// Validate a window handle and return the pointer to the object.
+//
+PWINDOW
+FASTCALL
+ValidateHwndOrDesk(HWND hwnd)
+{
+ if (hwnd == HWND_DESKTOP)
+ return GetThreadDesktopWnd();
+
+ return ValidateHwnd(hwnd);
+}
int STDCALL
MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints)
{
- POINT FromOffset, ToOffset;
- LONG XMove, YMove;
- ULONG i;
+ PWINDOW FromWnd, ToWnd;
+ POINT Delta;
+ UINT i;
- if (hWndFrom == NULL)
- {
- FromOffset.x = FromOffset.y = 0;
- } else
- if(!NtUserGetClientOrigin(hWndFrom, &FromOffset))
- {
- return 0;
- }
+ FromWnd = ValidateHwndOrDesk(hWndFrom);
+ if (!FromWnd)
+ return 0;
- if (hWndTo == NULL)
- {
- ToOffset.x = ToOffset.y = 0;
- } else
- if(!NtUserGetClientOrigin(hWndTo, &ToOffset))
- {
- return 0;
- }
- XMove = FromOffset.x - ToOffset.x;
- YMove = FromOffset.y - ToOffset.y;
+ ToWnd = ValidateHwndOrDesk(hWndTo);
+ if (!ToWnd)
+ return 0;
+
+ Delta.x = FromWnd->ClientRect.left - ToWnd->ClientRect.left;
+ Delta.y = FromWnd->ClientRect.top - ToWnd->ClientRect.top;
- for (i = 0; i < cPoints; i++)
+ for (i = 0; i != cPoints; i++)
{
- lpPoints[i].x += XMove;
- lpPoints[i].y += YMove;
+ lpPoints[i].x += Delta.x;
+ lpPoints[i].y += Delta.y;
}
- return(MAKELONG(LOWORD(XMove), LOWORD(YMove)));
+
+ return MAKELONG(LOWORD(Delta.x), LOWORD(Delta.y));
}
BOOL STDCALL
ScreenToClient(HWND hWnd, LPPOINT lpPoint)
{
- return(MapWindowPoints(NULL, hWnd, lpPoint, 1) != 0);
+ PWINDOW Wnd, DesktopWnd;
+
+ Wnd = ValidateHwnd(hWnd);
+ if (!Wnd)
+ return FALSE;
+
+ DesktopWnd = GetThreadDesktopWnd();
+
+ lpPoint->x += DesktopWnd->ClientRect.left - Wnd->ClientRect.left;
+ lpPoint->y += DesktopWnd->ClientRect.top - Wnd->ClientRect.top;
+
+ return TRUE;
}
BOOL STDCALL
ClientToScreen(HWND hWnd, LPPOINT lpPoint)
{
- return (MapWindowPoints( hWnd, NULL, lpPoint, 1 ) != 0);
+ PWINDOW Wnd, DesktopWnd;
+
+ Wnd = ValidateHwnd(hWnd);
+ if (!Wnd)
+ return FALSE;
+
+ DesktopWnd = GetThreadDesktopWnd();
+
+ lpPoint->x += Wnd->ClientRect.left - DesktopWnd->ClientRect.left;
+ lpPoint->y += Wnd->ClientRect.top - DesktopWnd->ClientRect.top;
+
+ return TRUE;
}