Fun with SetWorldTransform | CodeGuru

Fun with SetWorldTransform

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 13, 2003
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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 structure
XFORM 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 );

Downloads


Download demo project – 8 Kb


Download source – 22 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.