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

    inmovable scrollbars

    I'm learning on my own how drawing icons, scaling, and scrolling using Visual C++. My project is to place any icon in the child window, zoom in or out, and scroll anywhere. I am able to place icons with a rectangle around the icon, zoom in (out is just as easy and I'll include it later), BUT I can't scroll. The scroll bars will change size as I zoom in. However, the scroll bars don't scroll but return to their original location after I try to drag them even though they change size depending on the scale I'm using. What can I do? I included the relevant parts of code in CScrollView as I don't use the CDocument or anything else.



    I right click to zoom in use the OnRButton message:

    // Increment the scale to zoom in and set the scrollbar size
    void CME6View::OnRButtonUp(UINT nFlags, CPoint point)
    {
    m_Scale++;
    CClientDC theCDC(this);
    OnPrepareDC(&theCDC);
    SetScrolling();
    InvalidateRect(0);

    CScrollView::OnRButtonUp(nFlags, point);
    }



    Here's my OnPrepareDC code. I use GetClipBox to cause window extent to be the size of visible window instead of a CSize variable in the document as most examples use. I make sure to subtract the BottomRight from the TopLeft so that the BottomRight is larger than normal in the I have scrolled as in VRx and VRy.

    void CME6View::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
    {
    CScrollView::OnPrepareDC(pDC, pInfo);

    CME6Doc* pDoc = GetDocument();

    pDC->GetClipBox(m_VisRect);// Visible rectangles in pixels

    int VRx = m_VisRect.BottomRight().x - m_VisRect.TopLeft().x;
    int VRy = m_VisRect.BottomRight().y - m_VisRect.TopLeft().y;

    pDC->SetMapMode(MM_ANISOTROPIC);

    int PpIX = pDC->GetDeviceCaps(LOGPIXELSX);// pixels / inch - x
    int PpIY = pDC->GetDeviceCaps(LOGPIXELSY);// pixels / inch - y

    // Calculating the window
    int WEx = VRx / PpIX;
    if(WEx < 1) // To prevent the window extent x-coord from being zero
    WEx = 1;
    int WEy = VRy / PpIY;
    if(WEy < 1) // To prevent the window extent y-coord from being zero
    WEy = 1;

    // Calculating the viewport extent
    int VEx = WEx * m_Scale;
    int VEy = WEy * m_Scale;

    // For troubleshooting
    //AfxMessageBox(_T("ClipBox: " + ToStringI(VRx) + ", " + ToStringI(VRy) + "\npixels / inch: " + ToStringI(PpIX) + ", " + ToStringI(PpIY) + "\nWE: " + ToStringI(WEx) + ", " + ToStringI(WEy) + "\nVE: " + ToStringI(VEx) + ", " + ToStringI(VEy)), MB_OK);

    pDC->SetWindowExt(WEx, WEy);
    pDC->SetViewportExt(VEx, VEy);
    }



    This is how I set the scroll bar sizes:

    // Set the scroll bars
    void CME6View::SetScrolling()
    {
    SetScrollSizes(MM_TEXT, CSize((m_VisRect.BottomRight().x - m_VisRect.TopLeft().x) * m_Scale, (m_VisRect.BottomRight().y - m_VisRect.TopLeft().y) * m_Scale));
    }



    I had oringially used OnInitialUpdate but I have left it blank to set up scrollbars after zooming

    // Not using this as it's not initially important
    void CME6View::OnInitialUpdate()
    {
    CScrollView::OnInitialUpdate();
    }


    Please help.
    Zack

  2. #2
    Join Date
    Jan 2007
    Location
    Italy
    Posts
    156

    Re: inmovable scrollbars

    Hard to understand code without [code][/code] tag...

    Anyway, I don't think you can call directly OnPrepareDC()... It is called by the framework when it is needed, in response to an appropriate window message being sent where needed... I suggest not to mess with function that start with On---, because they are message handlers, and usually don't work outside their context
    Last edited by Buzzyous; January 19th, 2009 at 09:38 PM.
    - Buzzyous -

  3. #3
    Join Date
    Aug 2008
    Posts
    8

    Re: inmovable scrollbars

    Does that explain why I can zoom in but the scroll bars don't move?

Tags for this Thread

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