Coordinate mapping.
For those
who prefer to think in terms of formulae, here is how
device coordinates (Dx and Dy) are derived from logical
coordinates (Lx and Ly) and vice versa, using the window
and viewport origin (xWo and yWO, xVO and yVO), and window
and viewport extent (xWE and yWE, xVE and yVE) values:
Dx = (Lx Ð xWO) * xVE/xWE + xVO
Dy = (Ly Ð yWO) * yVE/yWE + yVO
Lx = (Dx Ð xVO) * xWE/xVE + xWO
Ly = (Dy Ð yVO) * yWE/yVE + yWO
The CDC
class does not directly support world coordinate
transformations that are available in Windows NT. To use
world coordinate transforms, applications may need to call
the Windows function SetWorldTransform directly.
The CDC
class provides a set of coordinate transformation
functions that can be used to obtain logical coordinates
from physical coordinates or vice versa. These functions
are DPtoLP and LPtoDP; both of these functions have
several overloaded versions that enable them to be used on
points, rectangles, and SIZE objects, or MFC classes that
encapsulate these objects (CPoint,
CRect, CSize).
Additional
transformation functions include DPtoHIMETRIC,
HIMETRICtoDP, LPtoHIMETRIC, and
HIMETRICtoLP. These
functions are particularly useful for OLE applications.
OLE objects are usually measured in HIMETRIC units; these
functions provide a direct means of transforming those
units directly into physical or
logical coordinates or
vice versa.
Coordinate
mapping is used extensively in views (that is, classes
derived from CView). In these classes, the member function
OnPrepareDC is used to set up coordinate mapping that
appropriately reflects the view and its current state. For
example, in scroll views, OnPrepareDC is used by the
framework to displace the window and/or viewport origin to
reflect the amount by which the view client area is
scrolled. Applications that wish to implement features
such as zooming can do so, for example, by overriding
CView::OnPrepareDC and changing the window or
viewport
extent.
Note:
UCanCode Advance E-XD++
CAD Drawing and Printing Solution
Source Code Solution for C/C++, .NET V2024 is released!
Contact UCanCode Software
To buy the source code or learn more about with: