Environment: VC6, MFC
This code will show you how useful SetWorldTransform can be. The code will enable you to do things such as:
- Scale to 1/2 of the original size
- Translate right by 3/4 inch
- Rotate 30 degrees counterclockwise
- Shear along the x-axis with a proportionality constant of 1.0
- Reflect about a horizontal axis
The code was originally part of the MS SDK, but I have enhanced and converted it to MFC to make it easier to understand.
// The Key part to the source code is using ‘SetWorldTransform’
// and setting up the XFORM structureXFORM xForm;
SetGraphicsMode ( pDC->GetSafeHdc (), GM_ADVANCED );
pDC->SetMapMode ( MM_LOENGLISH );xForm.eM11 = (FLOAT) 0.5;
xForm.eM12 = (FLOAT) 0.0;
xForm.eM21 = (FLOAT) 0.0;
xForm.eM22 = (FLOAT) 0.5;
xForm.eDx = (FLOAT) 0.0;
xForm.eDy = (FLOAT) 0.0;
SetWorldTransform ( pDC->GetSafeHdc (), &xForm );