For beginners of Windows programming, the most difficult part of GDI programming is the mapping mode (Mapping modes).
What is mapping mode?
We know that GDI drawing is performed on a display plane in the logical sense of the device description table, which uses logical coordinates, which simply means that the mapping pattern is the property of the device description table and is used to determine how to convert from logical coordinates to device coordinate values.
Windows supports the mapping mode in 8: Mm_text is the default.
/* Mapping Modes
#define Mm_text 1
#define Mm_lometric 2
#define Mm_himetric 3
#define Mm_loenglish 4
#define Mm_hienglish 5
#define Mm_twips 6
#define Mm_isotropic 7
#define Mm_anisotropic 8
*/
cdc* PDC = GetDC ();
Default mapping mode Mm_text
Pdc->ellipse (0, 0, 100, 100);
Set mapping mode Mm_lometric y down to negative 0.1mm
Pdc->setmapmode (Mm_lometric);
Pdc->ellipse (0, 0, 100,-100);
Set mapping mode Mm_himetric y down to negative 0.01mm
Pdc->setmapmode (Mm_himetric);
Pdc->ellipse (0, 0, 100,-100);
Set mapping mode Mm_loenglish y down to negative 0.01in 0.254mm 1 inch (in) = 25.4 mm (mm)
Pdc->setmapmode (Mm_loenglish);
Pdc->ellipse (0, 0, 100,-100);
Set mapping mode Mm_hienglish y down to negative 0.001in 0.0254mm 1 inch (in) = 25.4 mm (mm)
Pdc->setmapmode (Mm_hienglish);
Pdc->ellipse (0, 0, 100,-100);
Set mapping mode mm_twips y down to negative 0.0007in 1 inch (in) = 25.4 mm (mm)
Pdc->setmapmode (mm_twips);
Pdc->ellipse (0, 0, 100,-100);
/* Programmable mapping Mode */
Automatically adjusts the output size of the paint proportionally to the window size
CRect rect;
GetClientRect (&rect);
Anisotropic mm_anisotropic
Pdc->setmapmode (Mm_anisotropic);
Pdc->setwindowext (100, 100);
Pdc->setviewportext (rect. Width (), Rect. Height ());
Pdc->ellipse (0, 0, 100, 100);
Pdc->setmapmode (Mm_anisotropic);
Pdc->setwindowext (100,-100);
Pdc->setviewportext (rect. Width (), Rect. Height ());
Pdc->ellipse (0, 0, 100,-100);
Isotropic Mm_isotropic
Pdc->setmapmode (Mm_isotropic);
Pdc->setwindowext (100,-100);
Pdc->setviewportext (rect. Width (), Rect. Height ());
Pdc->ellipse (0, 0, 100,-100);
Pdc->setmapmode (Mm_isotropic);
Pdc->setwindowext (100,-100);
Pdc->setviewportext (rect. Width (), Rect. Height ());
Pdc->ellipse (0, 0, 100,-100);
Cdc::setwindowext setting "window range"
Cdc::setviewportext setting "Viewport range"
It can be argued that the dimensions of the window are calculated in logical units and the dimensions of the viewport are calculated as device dimensions or pixel points.
It is important to note that in Mm_isotropic mode, you should call SetWindowExt first, or the client area of a partial window may not be available because it falls outside the logical bounds of the window.
GDI mapping patterns in Windows drawings