SetViewportExt

2.x

  DWORD SetViewportExt(hdc, nXExtent, nYExtent)    
  HDC hdc; /* handle of device context */
  int nXExtent; /* x-extent of viewport, */  
  int nYExtent; /* y-extent of viewport, */  

The SetViewportExt function sets the x- and y-extents of the viewport of the given device context. The viewport, along with the window, defines how points are converted from logical coordinates to device coordinates.

Parameters

hdc

Identifies the device context.

nXExtent

Specifies the x-extent, in device units, of the viewport.

nYExtent

Specifies the y-extent, in device units, of the viewport.

Return Value

The return value is the previous viewport extents, in device units, if the function is successful. The low-order word contains the previous x-extent; the high-order word contains the previous y-extent. Otherwise, the return value is zero.

Comments

When the following mapping modes are set, calls to the SetWindowExt and SetViewportExt functions are ignored:

MM_HIENGLISH
MM_HIMETRIC
MM_LOENGLISH
MM_LOMETRIC
MM_TEXT
MM_TWIPS

When the mapping mode is MM_ISOTROPIC, an application must call the SetWindowExt function before calling SetViewportExt.

The x- and y-extents of the viewport define how much the graphics device interface (GDI) must stretch or compress units in the logical coordinate system to fit units in the device coordinate system. For example, if the x-extent of the window is 2 and the x-extent of the viewport is 4, GDI converts two logical units (measured from the x-axis) into four device units. Similarly, if the y-extent of the window is 2 and the y-extent of the viewport is –1, GDI converts two logical units (measured from the y-axis) into one device unit.

The extents also define the relative orientation of the x- and y-axes in both coordinate systems. If the signs of matching window and viewport extents are the same, the axes have the same orientation. If the signs are different, the orientation is reversed. For example, if the y-extent of the window is 2 and the y-extent of the viewport is –1, GDI converts the positive y-axis in the logical coordinate system to the negative y-axis in the device coordinate system. If the x-extents are 2 and 4, GDI converts the positive x-axis in the logical coordinate system to the positive x-axis in the device coordinate system.

Example

The following example uses the SetMapMode, SetWindowExt, and SetViewportExt functions to create a client area that is 10 logical units wide and 10 logical units high, and then draws a rectangle that is 4 logical units wide and 4 logical units high:

HDC  hdc;
RECT rc;

GetClientRect(hwnd, &rc);
hdc = GetDC(hwnd);
SetMapMode(hdc, MM_ANISOTROPIC);
SetWindowExt(hdc, 10, 10);
SetViewportExt(hdc, rc.right, rc.bottom);
Rectangle(hdc, 3, 3, 7, 7);
ReleaseDC(hwnd, hdc);

See Also

GetViewportExt, SetWindowExt