int SetMapMode(hdc, fnMapMode) | |||||
HDC hdc; | /* handle of device context | */ | |||
int fnMapMode; | /* mapping mode to set | */ |
The SetMapMode function sets the mapping mode of the given device context. The mapping mode defines the unit of measure used to convert logical units to device units; it also defines the orientation of the device's x- and y-axes. GDI uses the mapping mode to convert logical coordinates into the appropriate device coordinates.
hdc
Identifies the device context.
fnMapMode
Specifies the new mapping mode. This parameter can be any one of the following values:
Value | Meaning |
MM_ANISOTROPIC | Logical units are converted to arbitrary units with arbitrarily scaled axes. Setting the mapping mode to MM_ANISOTROPIC does not change the current window or viewport settings. To change the units, orientation, and scaling, an application should use the SetWindowExt and SetViewportExt functions. |
MM_HIENGLISH | Each logical unit is converted to 0.001 inch. Positive x is to the right; positive y is up. |
MM_HIMETRIC | Each logical unit is converted to 0.01 millimeter. Positive x is to the right; positive y is up. |
MM_ISOTROPIC | Logical units are converted to arbitrary units with equally scaled axes; that is, one unit along the x-axis is equal to one unit along the y-axis. The SetWindowExt and SetViewportExt functions must be used to specify the desired units and the orientation of the axes. GDI makes adjustments as necessary to ensure that the x and y units remain the same size. |
MM_LOENGLISH | Each logical unit is converted to 0.01 inch. Positive x is to the right; positive y is up. |
MM_LOMETRIC | Each logical unit is converted to 0.1 millimeter. Positive x is to the right; positive y is up. |
MM_TEXT | Each logical unit is converted to one device pixel. Positive x is to the right; positive y is down. |
MM_TWIPS | Each logical unit is converted to 1/20 of a point. (Because a point is 1/72 inch, a twip is 1/1440 inch). Positive x is to the right; positive y is up. |
The return value is the previous mapping mode, if the function is successful.
The MM_TEXT mode allows applications to work in device pixels, where one unit is equal to one pixel. The physical size of a pixel varies from device to device.
The MM_HIENGLISH, MM_HIMETRIC, MM_LOENGLISH, MM_LOMETRIC, and MM_TWIPS modes are useful for applications that must draw in physically meaningful units (such as inches or millimeters).
The MM_ISOTROPIC mode ensures a 1:1 aspect ratio, which is useful when it is important to preserve the exact shape of an image.
The MM_ANISOTROPIC mode allows the x- and y-coordinates to be adjusted independently.
The following example uses the SetMapMode function to set the mapping mode to MM_TWIPS and then uses the CreateFont function to create an 18-point logical font:
HFONT hfont, hfontOld;
int MapModePrevious, iPtSize = 18;
PSTR pszFace = "MS Serif";
MapModePrevious = SetMapMode(hdc, MM_TWIPS);
hfont = CreateFont(-iPtSize * 20, 0, 0, 0, 0, /* specify pt size */
0, 0, 0, 0, 0, 0, 0, 0, pszFace); /* and face name only */
hfontOld = SelectObject(hdc, hfont);
TextOut(hdc, 100, -500, pszFace, strlen(pszFace));
SetMapMode(hdc, MapModePrevious);
SelectObject(hdc, hfontOld);
DeleteObject(hfont);