Click here to Skip to main content
15,666,844 members
Articles / Desktop Programming / MFC
Posted 17 Nov 2002


19 bookmarked

EMF Record Rotation for EMR_POLYGON16

Rate me:
Please Sign up or sign in to vote.
2.71/5 (4 votes)
17 Nov 20022 min read
EMF record rotation for EMR_POLYGON16

Sample Image - MROT.jpg


When I decided to build a PowerPoint-like visual editor, the first thing I had to do was pasting clipboard contents to my view. But it's all around MSDN, CodeGuru, etc. like DrawCli, JTDraw, etc.

But the second part, when I had to rotate clipboard image, it was different. I could not find any hints at all.

Maybe it's because of my poor ability to search for things.. :( Anyway, I decided to rotate EMF.

The API function SetWorldTransform() is not supported on Win98. Actually, I'm working on Win2K, but I wanted to rotate EMF without any GDI transformation functions.

I think the steps to rotate EMF image are as follows:

  1. Draw COleClientItem inherited object to CMetaFileDC(A_DC).
  2. Get EMF from A_DC.
  3. Draw acquired EMF bits as rotated on another CMetaFileDC(B_DC).
  4. Get EMF from B_DC.
  5. Draw rotated EMF file to output DC.

Enumerating EMF (or WMF) requires CALLBACK function. Global scope can be used, but I've put it into my CItem class as static member function. No-static member function cannot be used as CALLBACK function in EnumEnhMetaFile.

Included source files were built as the following sequence:

  1. Create new MFC (EXE) project with Ole Container options selected.
  2. CblahblahCntrItem class is the COleClientItem inherited class. So, if you want some properties in your item, put your things into C~~CntrItem class.
  3. Add ID_EDIT_PASTE event handler.
  4. Customize draw function.

That's all!

Download project & build. Run MROT and get some vector image on your system's clipboard, and paste into MROT.

Then you can see the clipart on MROT's view. Then push RIGHT or LEFT cursor key. Then, the image will rotate by 5 in degrees.

MROT handles only EMR_POLYGON16 record. So, If your clipart contains other polygonal records or rectangular records... MROT cannot display & rotate it well.

MSDN\TECHART\1619\EMFDCODE.EXE on you MSDN CD can help you inspect your source clipart.

Now I think, building PowerPoint-like visual editor is not difficult (I say editor..:)) but will take long time if you approach as what I did. I'll move to GDI+, because I don't have to convert any polygon points at all.

P.S.: You may wonder what ConvertEMF member function is for. Some cliparts have their own mapping aspects. Mapmode as MM_ANISOTROPIC, and Window/Viewport Extents inversed... so, same rotation command will act differently on those kind of cliparts... ConvertEMF converts WindowExt inversed cliparts to non-inversed one.

Is there anyone to handle all of EMF records to rotate? :)


This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.

Written By
Web Developer
Korea (Republic of) Korea (Republic of)
Lazy Programmer since 1998.

Comments and Discussions

GeneralEasy way to rotate - using GDI+ Pin
Devin20-Nov-02 15:40
Devin20-Nov-02 15:40 
GeneralRe: Easy way to rotate - using GDI+ Pin
Sunil TG4-Nov-07 21:30
Sunil TG4-Nov-07 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.