MORE INFORMATION
The following file is available for download from the Microsoft Download Center:
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
An application uses the
SetViewportExt(),
SetViewportOrg(),
SetWindowExt(), and
SetWindowOrg() to align the two separate coordinate systems that the Windows graphics device interface (GDI) provides.
SetWindowOrg() and
SetViewportOrg() provide a one-to-one mapping of the two specified origin points (one in each coordinate system). The
SetWindowExt() and
SetViewportExt() functions instruct GDI how much to stretch (or compress)
the coordinate system after mapping the two specified points to each other.
The following code, drawn from the SHAPES sample, maps point (-10,
110) in the logical coordinate system to point (0, 0) in the client
coordinate system. Then the code sets the width of the viewport to 120
logical units and the height of the viewport to -120 logical units.
RECT ClientRect;
GetClientRect(hDC, ClientRect);
SetWindowOrg(hDC, -10, 110);
SetViewportOrg(hDC, 0, 0);
SetWindowExt(hDC, 120, -120);
SetViewportExt(hDC,
(short)(ClientRect.right - ClientRect.left),
(short)(ClientRect.bottom - ClientRect.top));
Negative coordinate scaling is required because the specified origin
point is above the displayed image. These concepts are perhaps best
illustrated on graph paper. Consider the following example. In the
logical coordinate system, an image of a star starts in the upper-left
quadrant of the coordinate system, between (-10, 110) and (110, -10).
Mark the specified origin (-10, 110) on the graph paper. To include
the image of the star in the viewport, the viewport "extent" must
include 120 units to the right (positive
x direction) and 120 units
down (negative
y direction). The specified viewport extents provide
the required viewport.
In the example, the left and top members of the
ClientRect data
structure are always zero. The subtraction is unnecessary but included
to demonstrate how the application aligns the rectangles in the
logical and client coordinate systems.
To reduce the size of the star, reduce the size of the viewport by
reducing the size of the arguments to
SetViewportExt(), or increase the amount of logical area mapped into the viewport by increasing the
arguments to
SetWindowExt().
The easiest method of becoming familiar with these functions is to
change only one argument value at a time, and change it by only a
small amount. For example, start by changing the preceding code to include
the following:
SetWindowOrg(hDC, -30, 110);
Changing the window origin in this manner trims some of the right side
of the star from the screen. Change the window origin back to its
original location, then change other values. You may need to change
the viewport coordinates by a larger amount than the window
coordinates to see the changes.
Changing one coordinate at a time is effective only in the
MM_ANISOTROPIC mapping mode, which allows the units in the coordinate
system to be rectangular rather than square. An application can change
units on the y-axis without changing the x-axis, and vice versa. In
contrast, the MM_ISOTROPIC mapping mode enforces square units, with an
equivalent measure along each axis.