Solved

Using SetMapMode()

Posted on 1998-05-11
5
572 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
notReplace  challenge 53 102
no14 challenge 14 57
building a service to accessed via telnet client, want colors ? 4 78
firstChar challenge 13 86
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now