Windows maps logical coordinates specified in GDI functions to device coordinates. Before we discuss the logical coordinate systems used with the various mapping modes, let's examine the different device coordinate systems that Windows defines for the video display area. Although we have been working mostly within the client area of our window, Windows uses two other device coordinate areas at various times. In all device coordinate systems, units are in terms of pixels. Values on the horizontal, or x, axis increase from left to right, and values on the vertical, or y, axis increase from top to bottom.
When we use the entire screen, we are working in terms of ”screen coordinates.“ The upper left corner of the screen is the point (0, 0). Screen coordinates are used in the WM_MOVE message (for nonchild windows) and in the following Windows functions: CreateWindow and MoveWindow (both for nonchild windows), GetMessagePos, GetCursorPos, SetCursorPos, GetWindowRect, WindowFromPoint, and SetBrushOrg. These are generally either functions that don't have a window associated with them (such as the two cursor functions) or functions that must move (or find) a window based on a screen point. If you use CreateDC with a ”DISPLAY“ parameter to obtain a device context for the entire screen, then logical coordinates specified in GDI calls will be mapped to screen coordinates.
”Whole-window coordinates“ refer to a program's entire window, including the caption bar, menu, scroll bars, and window frame. For a normal window, the point (0, 0) is the upper left corner of the sizing border. Whole-window coordinates are rare in Windows, but if you obtain a device context from GetWindowDC, logical coordinates in GDI functions will be mapped to whole-window coordinates.
The third device coordinate system—the one we've been working with the most_ uses ”client-area coordinates.“ The point (0, 0) is the upper left corner of the client area. When you obtain a device context using GetDC or BeginPaint, logical coordinates in GDI functions are translated to client-area coordinates.
You can convert client-area coordinates to screen coordinates and vice versa using the functions ClientToScreen and ScreenToClient. You can also obtain the position and size of the whole window in terms of screen coordinates using the GetWindowRect function. These three functions provide enough information to translate from any one device coordinate system to any other.