Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Set Center of CExtScrollWnd through code Collapse All
Subject Author Date
jb lee May 25, 2005 - 9:10 AM

How can I set the view center of CExtScrollWnd derived class with percentage of each horizontal/vertical location value?


Part of code below assure target point located at top-left corner of view, but, I wanna calculated p to be center of view.


For example, when the xPercent, yPercent each is 50, then center of view window will display center of all view content. 



 CSize sz = m_wndView.OnSwGetTotalSize();
 CPoint p;
 p.x = sz.cx * xPercent / 100.0;
 p.y = sz.cy * yPercent / 100.0;
 m_wndView.OnSwSetScrollPos( p );


TIA,


JB.

Technical Support May 25, 2005 - 12:13 PM

It seems the following source code is what you are asking about:

    bool bHorzScrollBarPresent =
        OnSwHasScrollBar( true );
    bool bVertScrollBarPresent =
        OnSwHasScrollBar( false );
    if(     bHorzScrollBarPresent
        ||  bVertScrollBarPresent
        )
    {
        CSize _sizeTotal =
            OnSwGetTotalSize();
        CSize _sizePage =
            OnSwGetPageSize( 0 );
        CPoint _ptCenter(
            bHorzScrollBarPresent
                ? ::MulDiv(
                    _sizeTotal.cx - _sizePage.cx,
                    50,
                    100
                    )
                : 0,
            bVertScrollBarPresent
                ? ::MulDiv(
                    _sizeTotal.cy - _sizePage.cy,
                    50,
                    100
                    )
                : 0
            );
        OnSwSetScrollPos( _ptCenter );
    }
The OnSwGetTotalSize() returns the size of the total scrollable data range in scrolling units. The scrolling limit value is the maximum scrolling position of the scroll bar control. The scrolling limit is less by one page size than the scrolling range. You just forgot this rule.