CSliderCtrl Logic question

I have a qustion about the logik to work with a CSliderCtrl on the HScroll event. I have a mp3 player where i use the slider for position in track.Moving the slider currently work well. But I also want that a click on the thumbtrack (the line, not the moveable button) will change the position of the Track and of the thumbbutton (moveable button).

My logik looks currently like in the code section. What I have to change so the position will changed if I click on the line (kumps to this position) and move the thumbbutton?
The Event m_hScrollEvent is setted to avoid incoming position events from the player.


void CPlayerPart2::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
	bool bRes;
 if (pScrollBar->GetSafeHwnd() == GetDlgItem(IDC_SLIDER_SONG)->GetSafeHwnd())
		if (SB_THUMBTRACK == nSBCode)
		else if (SB_ENDSCROLL == nSBCode)
		else if (SB_THUMBPOSITION == nSBCode)
			bRes = Mp3Lib::SeekPlayFile(nPos) ? true : false;
		CBDialog::OnHScroll(nSBCode, nPos, pScrollBar);

Open in new window

Who is Participating?
DanRollinsConnect With a Mentor Commented:
When the user clicks on the track, you will get an SB_PAGERIGHT or SB_PAGELEFT notif.  That's because clicking there is understood to be a request to jump forward or backward by one page (as with a normal scrollbar).
After this, you will get an SB_ENDSCROLL.  I believe that (short of subclassing the slider) you best bet would be to obtain the mouse position at the time of the click
   GetCursorPos Function
You would then need to convert to client coordinates to figure out where, on the track. the click occurred and use the SetPos function of CSliderCtrl) to move the thumb to that position.  Then you would take whatever action was intended by the user.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.