Using SetMapMode()

I would like to change the default map mode, so that my coordinates do this;
  X increases to the right.
  Y increases upward. (instead of default downward).

I use this to set the map mode to MM_ISOTROPIC:
mode      = pDC->SetMapMode( MM_ISOTROPIC );

But, now how do I specify that I want my Y to increase upward, and my X to increase to the right, and my 0,0 origin to be at some other position in the window?

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

mikeblasConnect With a Mentor Commented:
Whoops!  That's an answer, not a comment.

.B ekiM

CRect rect;

pDC->SetWindowExt(1, 1);
pDC->SetViewportExt(1, -1);
pDC->SetWindowOrg(0, 0);
pDC->SetViewportOrg(0, rect.bottom);

gunnAuthor Commented:
I stuck that code you put in my OnDraw() function; but it didn't work at all. In fact, my line I had drawn and showing, didn't show up after I stuck that in there.

You did not explain your code and why, so I am unable to figure out what is going on, to try and fix it. I'd like to learn too, not just plug in some code I don't understand.

So, if you can explain what should be happening here, and why its not for me, I'd appreciate it.

The SetWindowExt() would return values like (254,-254) and the SetViewportExt() would rturn values like (96,96). So putting in (1,1) and (1,-1) doesn't make quite sense..but I don't know what the 254 and 96 mean either so.........

You'll find that I answered the question as specifically as you asked it. You asked how, and I showed you; you didn't say you wanted to know why, too.

You didn't tell me what kind of window you're using, for example: are you doing this in a CView, or in a CScrollView?  In what kind of window have you written your code?  That your calls return non-identity values makes it sound like you're writing the code for a CScrollView, and CScrollView is incompatible with MM_ISOTROPIC and MM_ANISOTROPIC.

Have you set any other mapping mode elsewhere in your application? Did the view you're deriving from do it for you?

Mapping modes work by converting one set of coordinates (logical coordinates) to another set of coordinates (device coordinates). In MM_TEXT, device coordinates and logical coordinates are exactly the same.

In other mapping modes, a translation happens. Device coordinates always have (0,0) at the top left, and assign higher x- and y- values to each pixel on the way to the right and down, respectively.

When you call GDI routines, you always supply logical coordinates. If you're translating, you use these formuas:

Dx = ((Lx - WOx) * VEx / WEx) + VOx
Dy = ((Ly - WOy) * VEy / WEy) + VOy

Dx and Dy are the device X- and Y-coordinates drawn to after your translation.
Lx and Ly are the logical X- and Y-coordinates supplied by your call to whatever GDI routine you're using
WOy and WOx are the window x- and y- origins you gave to SetWindowOrg()
WEx and WEy are the window x- and y-extents you gave to SetWindowExt()
VEx and VEy are the viewport x- and y-extents you gave to SetViewportExt()
VOx and VOy are the viewport x- and y-extents you gave to SetViewportOrg()

So, if you code:

// CFlipView derives from CScrollView
void CFlipView::OnDraw(CDC* pDC)
   CFlipDoc* pDoc = GetDocument();

   CRect rect;


   pDC->SetWindowExt(1, 1);
   pDC->SetViewportExt(1, -1);
   pDC->SetWindowOrg(0, 0);
   pDC->SetViewportOrg(0, rect.bottom);


you'll end up with a chevron instead of a "v" because the Y-axis is flipped and the logical origin is set to the bottom left.

If you plug the numbers into the formulas I gave, you'll understand why.

.B ekiM

gunnAuthor Commented:
Thanks a lot. That explanation and sample code got me on the right track and I got my code working the way I wanted it to now.

btw, its a CFormView based app, with no scrolling. I'm using MM_ISOTROPIC, to change the y-coord where it's positive upward. You can see the app (if you're curious) at
All Courses

From novice to tech pro — start learning today.