How can I draw in REAL millimeters?

Posted on 2003-02-20
Medium Priority
Last Modified: 2008-01-16
I'm trying to display some fairly simple 2-d drawings in part of a dialog box, using VC++6.  They're schematics of objects (different from instance to instance of the dialog) but always about 60 to 120 mm wide, and somewhere around 50 to 100 mm high.
I'd *really* like it to display at exactly the same size it really is, but am not having conspicuous success.
I first tried setting mapping mode to MM_HIMETRIC, and multiplying all the dimensions of the object by 100.  But, for instance, a circle 70 mm in diameter comes out anywhere from 80 to 90 mm on the display.  The actual displayed size changes when I change my screen resolution.

The next thing I tried was to use GetDeviceCaps to find out the width in mm of the display, height in mm; width in pixels, height in lines... then did some math and mapping mode MM_ANISOTROPIC, thusly:

//(m_Canvas, here is the area in which I'm drawing):

int icx = m_Canvas.left+(m_Canvas.right-m_Canvas.left)/2;
int icy = m_Canvas.top+(m_Canvas.bottom-m_Canvas.top)/2;
dc.SetViewportOrg(icx, icy);

int iScreenWidthMM = dc.GetDeviceCaps(HORZSIZE);
int iScreenHeightMM = dc.GetDeviceCaps(VERTSIZE);
int iScreenWidthPixels = dc.GetDeviceCaps(HORZRES);
int iScreenHeightPixels = dc.GetDeviceCaps(VERTRES);
dc.SetWindowExt(iScreenWidthMM * 100,
               -iScreenHeightMM * 100);

...the sizing is coming out exactly the same as when I was using MM_HIMETRIC.

I'm a newbe to both VC++ and the Windows graphics API (as is most likely obvious).  If anyone would be so kind as to point me at a resource for this, I'd be most appreciative!  I've looked at many Internet sites, and have 3 or 4 "Beginning Visual C++" books by various authors, and none of them address this particular point.
Question by:JcP
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 7992364
you might get a fair exact length in one particular screen type with certain dot pitch. But if dot pitch is different for another screen, you won't be succesful.
LVL 49

Accepted Solution

DanRollins earned 200 total points
ID: 7992442
Imagine the circle drawn at a certain resolution on a 14-inch monitor, then imagine unplugging the cable and plugging it into a 21-inch monitor (no change to the circle or the resolution).  See the problem?  The circle will be much larger.  Now imagine that the user presses some buttons on this monitor to increase the scan width and/or height.  There it is again -- the sizing will be wrong.  Or think af a dual-monitor system with one small and one large monitor.  The user drags your window to the smaller monitor... and oops.  

There is no complete solution to this question.  You will need to make a 'best guess' -- using the factors that you are already using -- and then allow the user to  specify a scaling factor.

-- Dan

Expert Comment

ID: 7992715
I did not have problems using exact metric coordinates on CRT, the correct scaling is done by windows using the device driver of the painting device. Therefore You could get for example the same result on the screen as on the printer.
What I suggest is, try to use a normal window, not a dialog box (SDI Project in MFC) and make Your experiment with the dc of that window (selecting the MM_*METRIC coordinate system should be sufficient) and let us know (sorry, I do not have the possibility to test it right now ).


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 12

Expert Comment

ID: 7992726
You have to set the coordinates of the window to 'real coordinates'.

The problem is that a dialogbox uses 'dialog coordinates'. So the best way is to make a panel and inside that panel set the coordinate transformation to real coordinates.

You can set up that transformation by doing a Win32 function to set transformation. Forgot the exact name of the function but it is in the Win32 API. Just use the handle to the panel control (each control is also a window and have a window handle). Set the transformation of that window so that the point (1,1) is exactly 1 cm or 20 mm or whatever scale you want to the right (or left) and above (or below) of the origin (0,0). You can set both origin, orientation and scale factors and other parameters for the transformation but I also think there's an enum that can set to 'real coordinates' and then it will set all the parameters right without you having to figure out the coefficients for the transformation matrix yourself.

Also, remember that the coordinates is then different in that window than in any other window, the outer windows will still use the dialog transformation.

LVL 11

Expert Comment

ID: 7994745
Have a look in your monitor properties.  On Win 9x and XP, there is a "Dots per inch" DPI setting.  You'll have to convert it to metric but if you get that right, then you'll get the correct size metrically.

Expert Comment

ID: 8031621
Everyone seems to be ignoring the more direct physical properties of the monitor as well.  Ever used the vertical or horizontal size adjustments in a modern monitor?  All the other things are directly affected...   There is a reason that noone ever really attempts to do this on a monitor.  If you want life-size drawings, use a printer.  That's the only accurate solution.
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 9443226
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept dan rollins comment as answer

Please leave any comments here within the next seven days.

EE Cleanup Volunteer

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question