2

I'm using a third party library for drawing graphs. The library requires a HDC (GDI). But my application is using GDI+.

Q1: Is it safe to do this?

void f(Gdiplus::Graphics& graphics)
{
    HDC dc = graphics.GetHDC();

    // Call 3rd party lib functions using dc
    // ...

    graphics.ReleaseHDC(dc);
}

Q2: Some of the lib's functions require a bounding RECT struct (WinAPI). How do I calculate the coordinates for that rectangle if I'm using millimeters as page unit?

graphics.SetPageUnit(UnitMillimeter);
Pat
  • 1,726
  • 11
  • 18

1 Answers1

2

Q1: yes, but you may need to change the coordinate system if the third party library cannot handle your coordinates ==> Q2

Q2: this SO Question has some pointers for this (it is for the opposite direction, though), you will need to set the mapping mode to MM_HIMETRIC, convert your GDI+ coordinates to integers of 0.01 mm and use LPtoDP to get the pixel values.

Community
  • 1
  • 1
Edward Clements
  • 5,040
  • 2
  • 21
  • 27
  • Doesn't work for me. If I apply this method, I get negative values after the call to LPtoDP and the graph is drawn outside the visible area. Also, I've read that the MM_HIMETRIC mapping mode reverses the y-axis. This would seem to make sense combined with the negative values, but what about the origin then? – Pat Jun 10 '14 at 15:17
  • Some empirical tests, without changing the mapping mode, suggest that the unit is roughly 0.1mm. I could try to find a more accurate scaling factor, but that is dirty... – Pat Jun 10 '14 at 15:21
  • Sorry I forgot to mention the y axis, you should be able to use negative y; the link for the mapping mode in the answer also briefly describes two origins used by GDI (window and viewport) and the extents of each – Edward Clements Jun 10 '14 at 15:29