🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.misc
2 messages
2 total messages Started by Andy Deitsch Sun, 24 Jan 1993 01:10
DPtoLP question
#2291
Author: Andy Deitsch
Date: Sun, 24 Jan 1993 01:10
51 lines
2149 bytes
I'm trying to do something very simple.  I want to create a grid in
a window.  I'm using the MM_LOENGLISH map mode because I want the
space between grid lines to be the same no matter what the screen 
resolution.  The following is an excerpt from the code:

   SetMapMode(hDC, MM_LOENGLISH);
   GetClientRect(hDC, &rect);

   POINT PointsArray[2];

   PointsArray[0].x = rect.left;
   PointsArray[0].y = rect.top;
   PointsArray[1].x = rect.right;
   PointsArray[1].y = rect.bottom;

   DPtoLP(hDC, PointsArray, 2);

   const int space = 20;

   for (int x = PointsArray[0].x * space; 
         x < PointsArray[1].x * space; x += space)
   {
      MoveTo(hDC, x, PointsArray[0].y;
      LineTo(hDC, x, PointsArray[1].y;
   }


   for (int y = PointsArray[0].y * space;
         y < PointsArray[1].y * space; y += space)
   {
      MoveTo(hDC, PointsArray[0].x, y);
      LineTo(hDC, PointsArray[1].x, y);
   }


The first loop works fine, and the vertical lines are drawn correctly.
The problem is that DPtoLP is converting rect.bottom to a negative
number!  This obviously causes the second loop to next execute.  When
I look at rect in the debugger, rect.bottom is a positive number.  Why
is it getting translated to a negative?

If I comment out SetMapMode, then the grid is created, but it won't be
the same size on any screen.

Any help would be greatly appreciated.

-- 
_________________________________________________________________________
Andy Deitsch                             email    : deitsch@crd.ge.com  
GE Corporate Research & Development      phone    : (518) 387-7207   
Schenectday, NY 12301                    dial comm: 833-7207     
Re: DPtoLP question
#2299
Author: Chris Marriott
Date: Sun, 24 Jan 1993 17:40
52 lines
2805 bytes
In article <1993Jan24.011013.6436@crd.ge.com> deitsch@sol.crd.ge.com writes:

>I'm trying to do something very simple.  I want to create a grid in
>a window.  I'm using the MM_LOENGLISH map mode because I want the
>space between grid lines to be the same no matter what the screen 
>resolution.  The following is an excerpt from the code:
>
> [ source code deleted ]
>
>The first loop works fine, and the vertical lines are drawn correctly.
>The problem is that DPtoLP is converting rect.bottom to a negative
>number!  This obviously causes the second loop to next execute.  When
>I look at rect in the debugger, rect.bottom is a positive number.  Why
>is it getting translated to a negative?
>
>If I comment out SetMapMode, then the grid is created, but it won't be
>the same size on any screen.
>
>Any help would be greatly appreciated.
>
>-- 
>_________________________________________________________________________
>Andy Deitsch                             email    : deitsch@crd.ge.com  
>GE Corporate Research & Development      phone    : (518) 387-7207   
>Schenectday, NY 12301                    dial comm: 833-7207     
>

It's because the Y-axis in the *device* coordinate system increases
downwards, whereas it increases *upwards* in the MM_LOENGLISH coordinate
system.  Because the bottom your rectangle is below the top, it's at a
negative Y-coordinate.

There's a much easier way to do what you want, by the way.  Just use
"GetDeviceCaps" to find the resolution of the device (in pixels per inch),
and scale your grid that way.  If you do this, you can stay with the MM_TEXT
mapping mode.

eg, if you want lines spaced 1/4 of a logical inch apart, just say:

    int space = GetDeviceCaps( hDC, LOGPIXELS)/4;

Best wishes,

Chris
-- 
--------------------------------------------------------------------------
| Chris Marriott                           | chris@chrism.demon.co.uk    |
| Warrington, UK                           | BIX: cmarriott              |
|                                          | CIX: cmarriott              |
| Save the whales.  Collect the whole set. | CompuServe: 100113,1140     |
--------------------------------------------------------------------------
 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads