Solved

Using SetMapMode()

Posted on 1998-05-11
5
578 Views
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?


0
Comment
Question by:gunn
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1309712

CRect rect;
GetWindowRect(&rect);

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


0
 

Author Comment

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

?
0
 
LVL 11

Expert Comment

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

where:
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();
   ASSERT_VALID(pDoc);

   CRect rect;
   GetClientRect(rect);

   pDC->SetMapMode(MM_ANISOTROPIC);

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

   pDC->MoveTo(rect.TopLeft());
   pDC->LineTo(rect.CenterPoint());
   pDC->LineTo(rect.right, rect.top);
}

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

0
 
LVL 11

Accepted Solution

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

.B ekiM
0
 

Author Comment

by:gunn
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 http://www.radix.net/~gunn/hangar_gunnsite.html
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 66
cat dog challenge 18 127
Separate files macro - Errors on larger data set 18 73
Annoying "thing" blocks my view 4 117
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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…

821 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