Using SetMapMode()

Posted on 1998-05-11
Last Modified: 2013-11-20
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?

Question by:gunn
  • 3
  • 2
LVL 11

Expert Comment

ID: 1309712

CRect rect;

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


Author Comment

ID: 1309713
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.........

LVL 11

Expert Comment

ID: 1309714
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

LVL 11

Accepted Solution

mikeblas earned 50 total points
ID: 1309715
Whoops!  That's an answer, not a comment.

.B ekiM

Author Comment

ID: 1309716
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

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 157
not able to insert into temp table 68 162
building a service to accessed via telnet client, want colors ? 4 88
Capture logon name 13 73
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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