CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    4

    GDI Mapping Modes?

    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.

  2. #2
    Join Date
    Apr 1999
    Posts
    10

    Re: GDI Mapping Modes?

    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...

  3. #3
    Guest

    I'm looking for a Win32 API solution, not MFC.

    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?



  4. #4
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    418

    Re: I'm looking for a Win32 API solution, not MFC.

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured