ScreenToClient

2.x

  void ScreenToClient(hwnd, lppt)    
  HWND hwnd; /* window handle for source coordinates */
  POINT FAR* lppt; /* address of structure with coordinates */

The ScreenToClient function converts the screen coordinates of a given point on the screen to client coordinates.

Parameters

hwnd

Identifies the window whose client area is to be used for the conversion.

lppt

Points to a POINT structure that contains the screen coordinates to be converted. The POINT structure has the following form:

typedef struct tagPOINT {   /* pt */
   int x;
   int y;
} POINT;

For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

This function does not return a value.

Comments

The ScreenToClient function replaces the screen coordinates in the POINT structure with client coordinates. The new coordinates are relative to the upper-left corner of the given window's client area.

Example

The following example uses the GetWindowRect function to retrieve the screen coordinates for a specified window, calls the ScreenToClient function to convert the upper-left and lower-right corners of the window rectangle to client coordinates, and then reports the results in a message box:

RECT  rc;           /* window's screen coordinates      */
POINT ptUpperLeft;  /* client coordinate of upper left  */
POINT ptLowerRight; /* client coordinate of lower right */
char  szText[128];  /* char buffer for wsprintf         */

GetWindowRect(hwnd, &rc);

ptUpperLeft.x   = rc.left;
ptUpperLeft.y   = rc.top;
ptLowerRight.x  = rc.right;
ptLowerRight.y  = rc.bottom;

ScreenToClient(hwnd, &ptUpperLeft );
ScreenToClient(hwnd, &ptLowerRight);

wsprintf(szText,
    "S: (%d,%d)-(%d,%d) --> C: (%d,%d)-(%d,%d)",
    rc.left, rc.top, rc.right, rc.bottom,
    ptUpperLeft.x, ptUpperLeft.y, ptLowerRight.x, ptLowerRight.y);

MessageBox(hwnd, szText, "ScreenToClient", MB_OK);

See Also

ClientToScreen, MapWindowPoints