我的点击能够实现滚动条的移动了,但是不知道怎样实现拖动滚动条!

解决方案 »

  1.   

    要响应SB_THUMBTRACK消息
    然后调用SetScrollPos
      

  2.   

    头文件里添加 
      afx_msg void VScroll(UINT nSBCode, UINT nPos);.cpp文件里添加 
    BEGIN_MESSAGE_MAP(CDropScrollBar, CScrollBar)
    //{{AFX_MSG_MAP(CDropScrollBar)
               ……
    ON_WM_VSCROLL_REFLECT()
               ……
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    void C****ScrollBar::VScroll(UINT nSBCode, UINT nPos) 
    {
    // TODO: Add your message handler code here
    if( !m_pListBox )
    return; int nTop = m_pListBox->GetTopIndex();
    int nBottom = m_pListBox->GetBottomIndex(); SCROLLINFO info; info.cbSize = sizeof(SCROLLINFO);
    if( !GetScrollInfo( &info, SIF_ALL|SIF_DISABLENOSCROLL ) )
    return; switch( nSBCode )
    {
    case SB_BOTTOM: // Scroll to bottom.
    break; case SB_ENDSCROLL: // End scroll.
    break; case SB_LINEDOWN: // Scroll one line down.
    info.nPos++;
    if( info.nPos > info.nMax )
    info.nPos = info.nMax;
    m_pListBox->SetTopIdx( info.nPos );
    break; case SB_LINEUP: // Scroll one line up.
    info.nPos--;
    if( info.nPos < info.nMin )
    info.nPos = info.nMin;
    m_pListBox->SetTopIdx( info.nPos );
    break; case SB_PAGEDOWN: // Scroll one page down.
    info.nPos += info.nPage;
    if( info.nPos > info.nMax )
    info.nPos = info.nMax;
    m_pListBox->SetTopIdx( info.nPos );
    break; case SB_PAGEUP: // Scroll one page up.
    info.nPos -= info.nPage;
    if( info.nPos < info.nMin )
    info.nPos = info.nMin;
    m_pListBox->SetTopIdx( info.nPos );
    break; case SB_THUMBPOSITION: // Scroll to the absolute position. The current position is provided in nPos.
    info.nPos = nPos;
    m_pListBox->SetTopIdx( info.nPos );
    break; case SB_THUMBTRACK: // Drag scroll box to specified position. The current position is provided in nPos.
    info.nPos = nPos;
    m_pListBox->SetTopIdx( info.nPos );
    break; case SB_TOP: // Scroll to top. 
    break; }
    SetScrollInfo( &info );

    }
      

  3.   

    把m_pListBox部分干掉,修改一下即可