CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    79

    About ScrollView class

    Hello:
    I use VC++6.0 MFC ScrollView class.
    Beacuse I need use the automatic scrollbar,move my graphic.
    But now I need use map mode MM_ISOTROPIC/HIENGLISH draw graphic
    the code in OnDraw() function.
    --------------------------------------
    int nmapOld = pDC->GetMapMode();
    pDC->SetMapMode(MM_ISOTROPIC);
    pDC->SetWindowExt(Xmax,Ymax);
    pDC->SetViewportExt(m_cxClient,-m_cyClient);
    pDC->SetViewportOrg(m_cxClient/2,m_cyClient/2);
    CPen newpen;
    CBrush newbrush;
    newbrush.CreateSolidBrush(m_crColors[2]);
    newpen.CreatePen(PS_SOLID,8,RGB(255,0,0));
    CPen* oldpen;
    CBrush *oldbrush;
    oldbrush=pDC->SelectObject(&newbrush);
    oldpen=pDC->SelectObject(&newpen);
    pDC->MoveTo(10,10);
    pDC->LineTo(600,600);
    pDC->Rectangle(rect);
    pDC->SelectObject(oldpen);
    newpen.DeleteObject();
    pDC->SelectObject(oldbrush);
    newbrush.DeleteObject();
    pDC->SetMapMode(nmapOld);
    ---------------------------------------------
    THe question,Use MM_TEXT make graphic the result OK!
    But when I use MM_IOSTROPIC.The result wrong.
    Would your help me?
    I must setup myself map mode,and use scroll graphic.
    Welcome any advice!

    Yoh-hei


  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: About ScrollView class

    If MM_TEXT works OK, why do you want to use a different mapping mode?

    What exactly happens when you use the new mode?



    --
    Jason Teagle
    [email protected]

  3. #3
    Join Date
    Apr 1999
    Posts
    79

    Re: About ScrollView class

    Hello:
    That's right.But When I use MM_ISOTROPIC mode I can setup
    my Coordinate system.Like this:
    dc.SetWindowExt(Xmax,Ymax);
    dc.SetViewportExt(m_cxClient,-m_cyClient);
    dc.SetViewportOrg(m_cxClient/2,m_cyClient/2);
    And now the coordinate Center Point on the client screen center.
    The coordinate system's value is same with mathematics.
    But if I change the mode use MM_TEXT.The all graphic display
    is different ,(It's wrong).
    In fact I want use MM_TEXT mode.It can draw map if use ScrollView
    class.
    Question ues MM_TEXT mode.How to build coordinate system of myself
    like mathematics.
    Thank you very much.
    Waiting you replay.



  4. #4
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: About ScrollView class

    Well, one possibility is to have a CPoint member variable which holds the actual position within the view's DC that your (0, 0) will be. This would be set to be the centre of the view's client rectangle whenever the view is resized. For example, if the client area is 500 x 300, then your CPoint member would be set to (250, 150) - which is where the centre of the window is.

    Now, whenever you want to manipulate Cartesian co-ordinates (your system, with (0, 0) in the centre), simply add the member CPoint. To convert actual to Cartesian, do the reverse. You should define functions, like this:

    ---void CMyView::RepositionCartesianCentre(void)
    {
    // Should be called in response to a WM_SIZE message.

    CRect rctClient ;

    GetClientRect(&rctClient);
    m_ptCartesianCentre.cx = rctClient.Width() / 2 ;
    m_ptCartesianCentre.cy = rctClient.Height() / 2 ;
    }

    void CMyView::CartesianToActual(CPoint& ptPoint)
    {
    ptPoint += m_ptCartesianCentre ;
    }

    void CMyView::ActualToCartesian(CPoint& ptPoint)
    {
    ptPoint -= m_ptCartesianCentre ;
    }




    ---

    Remember, though, that if your CScrollView has been scrolled, the DC origin is not necessarily the same as the origin of the client area. When using OnDraw(), this has been taken care of; you don't have to do anything other than convert to your Cartesian. If you use (construct) a DC anywhere else, such as a CClientDC, you MUST call CScrollView::OnPrepareDC(&dcClient) to correct for this - if you do not, your drawing will be in the wrong place. These rules apply to actual co-ordinates; you will then need to convert to your Cartesian after this correction.

    Does this help?


    --
    Jason Teagle
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured