scrollbar 使用

要注意是誰響應WM_VSCROLL ,WM_HSCROLL,在對話框上添加scrollbar ,對話框要響應此消息。

 

 

 

void   CMyView::OnHScroll(UINT   nSBCode,   UINT   nPos,   CScrollBar*   pScrollBar)    
  {  
        //   Get   the   minimum   and   maximum   scroll-bar   positions.  
        int   minpos;  
        int   maxpos;  
        pScrollBar->GetScrollRange(&minpos,   &maxpos);    
        maxpos   =   pScrollBar->GetScrollLimit();  
   
        //   Get   the   current   position   of   scroll   box.  
        int   curpos   =   pScrollBar->GetScrollPos();  
   
        //   Determine   the   new   position   of   scroll   box.  
        switch   (nSBCode)  
        {  
        case   SB_LEFT:             //   Scroll   to   far   left.  
              curpos   =   minpos;  
              break;  
   
        case   SB_RIGHT:             //   Scroll   to   far   right.  
              curpos   =   maxpos;  
              break;  
   
        case   SB_ENDSCROLL:       //   End   scroll.  
              break;  
   
        case   SB_LINELEFT:             //   Scroll   left.  
              if   (curpos   >   minpos)  
                    curpos--;  
              break;  
   
        case   SB_LINERIGHT:       //   Scroll   right.  
              if   (curpos   <   maxpos)  
                    curpos++;  
              break;  
   
        case   SB_PAGELEFT:         //   Scroll   one   page   left.  
        {  
              //   Get   the   page   size.    
              SCROLLINFO       info;  
              pScrollBar->GetScrollInfo(&info,   SIF_ALL);  
         
              if   (curpos   >   minpos)  
              curpos   =   max(minpos,   curpos   -   (int)   info.nPage);  
        }  
              break;  
   
        case   SB_PAGERIGHT:             //   Scroll   one   page   right.  
        {  
              //   Get   the   page   size.    
              SCROLLINFO       info;  
              pScrollBar->GetScrollInfo(&info,   SIF_ALL);  
   
              if   (curpos   <   maxpos)  
                    curpos   =   min(maxpos,   curpos   +   (int)   info.nPage);  
        }  
              break;  
   
        case   SB_THUMBPOSITION:   //   Scroll   to   absolute   position.   nPos   is   the   position  
              curpos   =   nPos;             //   of   the   scroll   box   at   the   end   of   the   drag   operation.  
              break;  
   
        case   SB_THUMBTRACK:       //   Drag   scroll   box   to   specified   position.   nPos   is   the  
              curpos   =   nPos;           //   position   that   the   scroll   box   has   been   dragged   to.  
              break;  
        }  
   
        //   Set   the   new   position   of   the   thumb   (scroll   box).  
        pScrollBar->SetScrollPos(curpos);  
   
        CView::OnHScroll(nSBCode,   nPos,   pScrollBar);  
  }  

發佈了34 篇原創文章 · 獲贊 1 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章