SetWindowExt

2.x

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

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

Parameters

hdc

Identifies the device context.

nXExtent

Specifies the x-extent, in logical units, of the window.

nYExtent

Specifies the y-extent, in logical units, of the window.

Return Value

The return value is the window's previous extents, in logical 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 MM_ISOTROPIC mode is set, an application must call the SetWindowExt function before calling SetViewportExt.

The x- and y-extents of the window 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 units wide and 4 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

GetWindowExt, SetViewportExt