# How to convert screen coordinates

This is a discussion on How to convert screen coordinates within the Windows Programming forums, part of the Platform Specific Boards category; I am sure I am making this more difficult than it should be but here is my problem. I am ...

1. ## How to convert screen coordinates

I am sure I am making this more difficult than it should be but here is my problem.

I am trying to figure out how to convert the dimension of my client area from pixels to inches. I've read Petzolds book on viewports and device coordinates but I've only succeeded in freeze drying my brain!

For example lets say I want to draw a line from the left side of the client area over 2 inches like so (using MM_TWIPS map mode):
Code:
```	MoveToEx (hdc,0,250,NULL);
LineTo (hdc, 2*1440, 250);```
Now, lets say I want to incorporate a zoom feature in my program that will resize this line to fill the width of my client area.
I know the size of the client area (in pixels) from my WM_SIZE case:
Code:
```	case WM_SIZE:
cxClient = LOWORD (lParam);
cyClient = HIWORD (lParam);```
and I know that my line is 2 inches wide so If I can figure out how to convert pixels into inches or vice versa I can easily come up with a ratio to do this.

What I need is an explaination on how to do this type of conversion, because I have thoroughly confused myself!

2. Here is a discription of each mapping mode:

MM_ANISOTROPIC Logical units are converted to arbitrary units with arbitrarily scaled axes. Setting the mapping mode to MM_ANISOTROPIC does not change the current window or viewport settings. To change the units, orientation, and scaling, call the SetWindowExt and SetViewportExt member functions.
MM_HIENGLISH Each logical unit is converted to 0.001 inch. Positive x is to the right; positive y is up.
MM_HIMETRIC Each logical unit is converted to 0.01 millimeter. Positive x is to the right; positive y is up.
MM_ISOTROPIC Logical units are converted to arbitrary units with equally scaled axes; that is, 1 unit along the x-axis is equal to 1 unit along the y-axis. Use the SetWindowExt and SetViewportExt member functions to specify the desired units and the orientation of the axes. GDI makes adjustments as necessary to ensure that the x and y units remain the same size.
MM_LOENGLISH Each logical unit is converted to 0.01 inch. Positive x is to the right; positive y is up.
MM_LOMETRIC Each logical unit is converted to 0.1 millimeter. Positive x is to the right; positive y is up.
MM_TEXT Each logical unit is converted to 1 device pixel. Positive x is to the right; positive y is down.
MM_TWIPS Each logical unit is converted to 1/20 of a point. (Because a point is 1/72 inch, a twip is 1/1440 inch.) Positive x is to the right; positive y is up.

Now if you do the math per inch in say MM_TWIPS then your size would be 1440 for one inch or 2880 for two inches and so forth. Of course if you use MM_LOENGLISH then it is 100 per inch and 200 for two inches and on and on. I hope this clarifies this for you.

3. Velius thank you for the reply.
I think I understand what is going on now. Thanks again for taking to the time to explain something so remedial to me.

4. Not a problem. Happy Win32 API coding.

Popular pages Recent additions