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

    viewport origin,mapping mode, etc

    Hi,

    I am using a CScrollView as the base class for my view
    and want to use MM_LOENGLISH as the mapping mode.
    I want to change the origin from top-left to bottom-left.
    I also need to draw a set of axes at the origin. I am really
    confused with device coordinates, logical coordinates,
    setting the viewport origin, and how these things work
    together when drawing on the screen (in MM_LOENGLISH mode).
    Any help is appreciated.


  2. #2
    Guest

    Re: viewport origin,mapping mode, etc

    override OnPrepareDC in your view class.


    void CGridView::OnPrepareDC(CDC* pDC,CPrintInfo* pInfo)
    {
    pDC->SetMapMode(MM_LOENGLISH);

    CRect clientRect;
    GetClientRect(clientRect); // Find size of client view are in device pixels

    CSize size=GetTotalSize(); // Find size of ScrollView in device pixels
    size.cx=max(size.cx,clientRect.Width()); // use the larger of the client width or scroll width
    size.cy=max(size.cy,clientRect.Height()); // use the larger of the client height or scroll height

    CRect rect(CPoint(0,0),size); // create a view rectangle (if using a scroll coordinate it will be larger than the viewable area)
    pDC->DPtoLP(&rect); // convert the rectangle from device pixels to logical pixels

    pDC->SetWindowOrg(CPoint(0,-rect.Height())); // move the window origin down the height of the view (not always the same as viewable area)
    }






  3. #3
    Join Date
    Aug 2008
    Posts
    8

    Re: viewport origin,mapping mode, etc

    I'm having a problem with scrolling in which the rectangles I have drawn will incorrectly draw over the already existing rectangles when I scroll in either direction. Also, the visible rectangles are completely redrawn when I minimize and then restore the window but as if the origin moved upon scrolling. My code to draw the rectangles is

    CRect TempRect = pDoc->GetNode(i); // The points for the rectangle
    OnPrepareDC(pDC);
    pDC->DPtoLP(&TempRect);
    pDC->Rectangle(TempRect);

    And I used the code provided in OnPrepareDC but the problem didn't change. Any ideas?

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