DWORD ScaleViewportExt(hdc, nXNum, nXDenom, nYNum, nYDenom) | |||||
HDC hdc; | /* handle of device context | */ | |||
int nXNum; | /* amount by which current x-extent is multiplied | */ | |||
int nXDenom; | /* amount by which current x-extent is divided | */ | |||
int nYNum; | /* amount by which current y-extent is multiplied | */ | |||
int nYDenom; | /* amount by which current y-extent is divided | */ |
The ScaleViewportExt function modifies the viewport extents relative to the current values.
hdc
Identifies the device context.
nXNum
Specifies the amount by which to multiply the current x-extent.
nXDenom
Specifies the amount by which to divide the result of multiplying the current x-extent by the value of the nXNum parameter.
nYNum
Specifies the amount by which to multiply the current y-extent.
nYDenom
Specifies the amount by which to divide the result of multiplying the current y-extent by the value of the nYNum parameter.
The low-order word of the return value contains the x-extent, in device units, of the previous viewport if the function is successful; the high-order word contains the y-extent.
The new viewport extents are calculated by multiplying the current extents by the given numerator and then dividing by the given denominator, as shown in the following formulas:
nXNewVE = (nXOldVE * nXNum) / nXDenom
nYNewVE = (nYOldVE * nYNum) / nYDenom
The following example draws a rectangle that is 4 logical units high and 4 logical units wide. It then calls the ScaleViewportExt function and draws a rectangle that is 8 units by 8 units. Because of the viewport scaling, the second rectangle is the same size as the first.
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);
ScaleViewportExt(hdc, 1, 2, 1, 2);
Rectangle(hdc, 6, 6, 14, 14);
ReleaseDC(hwnd, hdc);