Understanding of ScrollBar Control

Source: Internet
Author: User

About ScrollBar only study up and down scrolling

1. First ScrollBar's parent window is Containerui, and regardless of which control wants to use the scrollbar, the space must be container or inherited container.

2. The function records the percentage of the scrollbar as a value of M_nscrollpos, and then records how many of the scroll bars are divided by M_nrange.

3. The scroll bar has four key icons: button1, button2, Thumb, Rail. The two buttons are two buttons on both ends, the thumb is the entire sliding button, and the rail is the small button in the middle of the entire slide button, both of which are obtained by dynamic calculation. The specific thumb calculation is in the SetPos function, while the rail button is determined by the position of the thumb, which is calculated and displayed directly in the Paintrail.

4, the size of the thumb is passed in the No. 479 line: int cythumb = cy * (rc.bottom-rc.top)/(M_nrange + rc.bottom-rc.top), calculated, that is, if the larger m_nrange then th The UMB is smaller relative to the entire scroll bar.

5, when the size of the entire scrollbar: button1 height +button2 height <m_cxyfixed.cy+m_cxyfixed.cy (here is two buttons are visible) when the thumb scroll bar does not display the No. 519 line::: ZeroMemory ( &m_rcthumb, sizeof (M_RCTHUMB)), and the size of the scroll bar to button1 and Button2.

6, then doevent if you click Button1 or button2 will trigger Containerui LineDown or up and then you can see Containerui linedown function, Linesize is a fixed size of 8, And the scroll bar is the default size of 16, but this is OK, because when the click LineDown or up, the position size of the change depends on the location of Containerui to change.

Line No. 551 of ScrollBar if (M_powner! = NULL) m_powner->lineup ()                     ; Else SetScrollPos (M_nscrollpos- m_nlinesize); // This means that when there is a container, it does not set the Scrollpos itself but sets the size by Containerui. 
View Code

And then look at the related lineup function of Containerui.

    voidCcontainerui::lineup () {intCyline =8; if(m_pmanager) Cyline = M_pmanager->getdefaultfontinfo ()->tm.tmheight +8; SIZE sz=GetScrollPos (); Sz.cy-=Cyline;    SetScrollPos (SZ); }//This clearly indicates that the linesize size is 8//the SetScrollPos function here does two things: 1, call ScrollBar's SetScrollPos function. 2. Move the elements up to the corresponding pixel.     voidCcontainerui::setscrollpos (SIZE szpos) {intCX =0; intcy =0; if(M_pverticalscrollbar && m_pverticalscrollbar->IsVisible ()) {            intIlastscrollpos = m_pverticalscrollbar->GetScrollPos (); M_pverticalscrollbar-SetScrollPos (szpos.cy); Cy= M_pverticalscrollbar->getscrollpos ()-Ilastscrollpos; }        if(M_phorizontalscrollbar && m_phorizontalscrollbar->IsVisible ()) {            intIlastscrollpos = m_phorizontalscrollbar->GetScrollPos (); M_phorizontalscrollbar-SetScrollPos (SZPOS.CX); CX= M_phorizontalscrollbar->getscrollpos ()-Ilastscrollpos; }        if(CX = =0&& cy = =0)return;        RECT Rcpos;  for(intIt2 =0; It2 < M_items. GetSize (); it2++) {Ccontrolui* Pcontrol = static_cast<ccontrolui*>(M_items[it2]); if(!pcontrol->isvisible ())Continue; if(Pcontrol->isfloat ())Continue; Rcpos= pcontrol->GetPos (); Rcpos.left-=CX; Rcpos.right-=CX; Rcpos.top-=Cy; Rcpos.bottom-=Cy; Pcontrol-SetPos (Rcpos);    } Invalidate (); }
View Code

The same pageup and PageDown are also set by the Contaierui function.

But the size of the scroll here is not a fixed size but a page size.

void Ccontainerui::P ageup ()    {        = getscrollpos ();         int ioffset = m_rcitem.bottom-m_rcitem.top-m_rcinset.top- m_rcinset.bottom;         if (M_phorizontalscrollbar && m_phorizontalscrollbar->isvisible ()) Ioffset-= m_phorizontalscrollbar-> getfixedheight ();         -= Ioffset;        SetScrollPos (SZ);    }
View Code

7. The SetTimer of the No. 546 line of UIScrollBar here is to trigger the movement when the PageUp or down (lineup and down are the same), or when the scroll bar is dragged. Specifically, you can see the Doevent function. The No. 660 line begins if the event. Type = = Uievent_timer && Event.wparam = = Default_timerid)

ScrollBar control's awareness

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.