Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How can I draw in REAL millimeters?

Posted on 2003-02-20
7
Medium Priority
?
394 Views
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);

dc.SetMapMode(MM_ANISOTROPIC);
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);
dc.SetViewportExt(iScreenWidthPixels,
                  iScreenHeightPixels);

...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.
0
Comment
Question by:JcP
7 Comments
 
LVL 5

Expert Comment

by:Kimpan
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.
0
 
LVL 49

Accepted Solution

by:
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
0
 

Expert Comment

by:cynick
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 ).


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Salte
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.

Alf
0
 
LVL 11

Expert Comment

by:cup
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.
0
 
LVL 2

Expert Comment

by:bkrahmer
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.
brian
0
 
LVL 41

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.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Ged
EE Cleanup Volunteer
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

581 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