2.6 Coordinate Functions

Coordinate functions convert client coordinates to screen coordinates (or vice versa). These functions are useful in graphics-intensive applications. Following are the coordinate functions:

Function Description

DPtoLP Converts device points (that is, points relative to the window origin) into logical points.
GetCurrentPosition Retrieves the current position, in logical coordinates.
GetCurrentPositionEx Retrieves position in logical units.
LPtoDP Converts logical points into device points.

GDI uses the following equations to transform logical points to device points and device points to logical points:

Transforming logical points to device points:

Dx = (LxxWO) * xVE/xWE + xVO
Dy = (LyyWO) * yVE/yWE + yVO

Transforming device points to logical points:

Lx = (DxxVO) * xWE/xVE + xWO
Ly = (DyyVO) * yWE/yVE + yWO

Following are descriptions of the variables used in these transformation equations:

Variable Description

xWO Window origin x-coordinate
yWO Window origin y-coordinate
xWE Window extent x-coordinate
yWE Window extent y-coordinate
xVO Viewport origin x-coordinate
yVO Viewport origin y-coordinate
xVE Viewport extent x-coordinate
yVE Viewport extent y-coordinate
Lx Logical-coordinate system x-coordinate
Ly Logical-coordinate system y-coordinate
Dx Device x-coordinate
Dy Device y-coordinate

The following four ratios are scaling factors used to determine the necessary stretching or compressing of logical units: xVE/xWE, yVE/yWE, xWE/xVE, and yWE/yVE.

The subtraction and addition of viewport and window origins is referred to as the translational component of the equation.

In addition, applications can use the following functions from the USER API to convert coordinates from one system to another:

Function Description

ChildWindowFromPoint Determines which, if any, of the child windows belonging to a given parent window contains a specified point.
ClientToScreen Converts the client coordinates of a given point on the display to screen coordinates.
ScreenToClient Converts the screen coordinates of a given point on the display to client coordinates.
WindowFromPoint Retrieves the handle of the window that contains a given point.

For more information about these USER functions, see Chapter 1, “Window Management.”