DWORD SetViewportOrg(hdc, nXOrigin, nYOrigin) | |||||
HDC hdc; | /* handle of device context | */ | |||
int nXOrigin; | /* x-coordinate of new origin | */ | |||
int nYOrigin; | /* y-coordinate of new origin | */ |
The SetViewportOrg function sets the viewport origin of the specified device context. The viewport, along with the window, defines how points are converted from logical coordinates to device coordinates.
hdc
Identifies the device context.
nXOrigin
Specifies the x-coordinate, in device coordinates, of the origin of the viewport. This value must be within the range of the device coordinate system.
nYOrigin
Specifies the y-coordinate, in device coordinates, of the origin of the viewport. This value must be within the range of the device coordinate system.
The return value is the coordinates of the previous viewport origin, in device units, if the function is successful. The low-order word contains the previous x-coordinate; the high-order word contains the previous y-coordinate. Otherwise, the return value is zero.
The viewport origin is the origin of the device coordinate system. The graphics device interface (GDI) converts points from the logical coordinate system to device coordinates. (An application can specify the origin of the logical coordinate system by using the SetWindowOrg function.) GDI converts all points in the logical coordinate system to device coordinates in the same way as it converts the origin.
The following example uses the SetViewportOrg function to set the viewport origin to the center of the client area and then draws a rectangle centered over the origin:
HDC hdc;
RECT rc;
GetClientRect(hwnd, &rc);
hdc = GetDC(hwnd);
SetViewportOrg(hdc, rc.right/2, rc.bottom/2);
Rectangle(hdc, -100, -100, 100, 100);
ReleaseDC(hwnd, hdc);