Vanvid
Vanvid

Reputation: 83

Get all position values from CScrollBar

Trying to use a CScrollBar in my MFC C++ application for Windows7.

I receive all messages just fine and have a handler that looks something like this:

void Dialog::OnHScroll(UINT nSBCode, UINT apos, CScrollBar* pScrollBar)
{    
    SCROLLINFO si;
    si.cbSize = sizeof( si );
    si.fMask = SIF_TRACKPOS;
    m_slider.GetScrollInfo(&si,SIF_TRACKPOS|SIF_POS|SIF_PAGE);
    int nTrackPos = si.nTrackPos; //0 except on TB_THUMBTRACK
    int nPos = si.nPos; //0 except on TB_THUMBTRACK
    UINT nPage = si.nPage; //seems correct always but I dont need it

The reason I try to extract the position using GetScrollInfo is because they may be bigger than what fits inside a 16bit var, and therefore I cannot use the pos being passed as the argument.

My problem however is that I only get a valid position when dragging the bar and receiving the TB_THUMBTRACK as well as the ending TB_ENDTRACK for drag operations. If I click in the scrollbar or use the arrows at each end all positions (argument pos, and everything in the SCROLLINFO struct except page) will be 0.

Does anyone know how to get the correct positions for all messages? Ie TB_LINEUP, TB_LINEDOWN etc.

Upvotes: 0

Views: 458

Answers (1)

Roger Rowland
Roger Rowland

Reputation: 26259

Take a look at the sample code for the WM_HSCROLL event handler that's shown in MSDN:

MSDN Documentation

Upvotes: 1

Related Questions