Click here to Skip to main content
15,671,843 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a drawn that I must slide with a's a temporal drawn, I have some blocks that represents time, they represents the processing of a machine..with this slide code doesn't work, drawn slide in an incorrect way.

this is code:

<pre>void CBtnTimeLine::Prova(int nPos)
	double d_inizio = 0.0;//

	double d_fine = (m_r2dClient.right - m_r2dClient.left) / m_dPixel_per_1Secondo;//

	double intervallo = (m_Time - ((m_r2dClient.right - m_r2dClient.left) / m_dPixel_per_1Secondo)) / 100;

	int		nDeltaXPixel = intervallo * m_dPixel_per_1Secondo;			// >0 diminuire start e stop

	double	dDeltaTime = 0.0;

	dDeltaTime = intervallo;		// riporta da Pixel->Secondi;

	m_dStartTime = d_inizio + nPos * intervallo;

	m_dStopTime = d_fine + nPos * intervallo;

	m_p2dPrev.x = m_dStartTime * m_dPixel_per_1Secondo;

Prova is the fuction that is called by scroll event

m_Time is the total time

What I have tried:

I tried the event of mouse event and in this case works, but I need scroll event with slide

void CBtnTimeLine::OnMouseMove(UINT nFlags, CPoint point)
		if (m_bDragInAction)
			if (((m_dStartTime >= 0)&&(m_dStopTime<= m_Time))|| ((m_dStartTime<0) && (point.x< m_p2dPrev.x))|| ((m_dStopTime> m_Time) && (point.x> m_p2dPrev.x)))
			int		nDeltaXPixel = point.x - m_p2dPrev.x;			// >0 diminuire start e stop
			double	dDeltaTime = 0.0;

			dDeltaTime = -nDeltaXPixel / m_dPixel_per_1Secondo;		// riporta da Pixel->Secondi;

			m_dStartTime += dDeltaTime;
			m_dStopTime += dDeltaTime;

			m_p2dPrev = point;
	CButton::OnMouseMove(nFlags, point);
Updated 24-Mar-23 6:52am

1 solution

Here's an example of this kind of thing in action : A smart edit and linked slider control[^].

The key thing is to service movement of the slider in the OnVScroll or OnHScroll message handler methods, depending on the orientation of your control. To set this up, define minimum and maximum values for the slider and then you have to translate a slider position to the appropriate value for your program. In the article linked, written by me incidentally, an edit box and a slider control are linked together so changing the slider sets the value in the edit control correspondingly. You may not need that functionality but the point is it demonstrates how to handle messages for movement of the slider.
Share this answer
Member 14594285 24-Mar-23 12:55pm    
yes but my problem is the drawn, beacuse is in pixel
Rick York 24-Mar-23 14:25pm    
I do not understand your reply. What you have to do is define a mapping between your application's minimum and maximum values to the slider's position limits and then translate the slider's position back to an appropriate value for your application. That's all there is to it. Handling mouse moves for a slider is NOT the right way to do this. If you want to move the mouse around and have your display respond to that then maybe a slider is not the right way to deal with it. I have done both of these - I have displays that I pan around when the user presses the left button down and then it stops when the button is released and no slider is involved in this. I also have displays that adjust themselves dynamically as a slider is moved. I also have displays that have both of these mechanisms combined but the slider is not affected when the user pans around. You need exactly how you want your display to work because it is not clear from your messages.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900