Click to See Complete Forum and Search --> : GDI Mapping Modes?


Nully
April 5th, 1999, 12:34 AM
I need a way to convert a size in MM_HIMETRIC units to MM_TEXT units.

It's bound to happen. You create a program using one mapping mode and lo and behold you end up needing to use a size measured in a different mapping mode (usually because you want to use code provided by someone else like a COM object).

Microsoft to my knowledge provides no API conversion functions for converting from one mapping mode to another. I don't understand why.

I have an ATL program that uses IPicture. IPicture has functions to obtain the width and height of the picture in MM_HIMETRIC units. My program uses MM_TEXT. Bounding rects are given to me in MM_TEXT. Neither IPicture, nor the ATL framework will return compatible coordinates and sizes.

This is frustrating and discouraging.

Is their way to convert a size in MM_HIMETRIC units to MM_TEXT units? Is it just me or are Microsoft developers really mad?


"Windows-based programming is strange. It's weird, it's warped, it's awkward, it's convoluted, it's mind-boggling. It's definitely not immediately obvious, and it may take some time before you experience the thrill of shouting "Eureka!" - Charles Petzold, highly aclaimed author of windows books.

David Swigger
April 5th, 1999, 01:49 AM
Hello,

Have you looked into the HIMETRICToDP
and DPToHIMETRIC functions?

David


Please don't tell me it's impossible. That just means I have to proove it...

April 5th, 1999, 03:26 AM
First, I'm looking for a Win32 API Solution. My application dose not support MFC and I want to keep it that way.

Second, what about other combinations like MM_TWIPS to MM_HIMETRIC?

I can convert logical coordinates to device coordinates, but how does that help me convert a size mesured in MM_HMETRIC to MM_TEXT?

Martin Speiser
April 5th, 1999, 05:53 AM
Hi,

I ran into the same problem from time to time. I usually do it this way: I get a DC based on the desktop, set it to the desired mapping mode, convert the coordinates with DPtoLP or LPtoDP, and then free the DC. This doesn't prevent you from the rounding errors, but it works.

In addition, somewhere deep in the documentation the conversion algorithm is described. But I found my solution easier to program ;-)




Martin