OnLButtonDown not getting called for Slider Control in MFC.?
-
Hi, I am using a slider control on a dialog box. I have handled OnLButtonDown for Slider control. But I wonder its not getting called whenever I click on the slider thumb, instaed it gets called when I click anywhere on the dialog. I want to handle OnLButtonDown when I click on the slider thumb. Anybody have any idea where is the issue.? Any help will be appreciated. Regards, Mbatra
-
Hi, I am using a slider control on a dialog box. I have handled OnLButtonDown for Slider control. But I wonder its not getting called whenever I click on the slider thumb, instaed it gets called when I click anywhere on the dialog. I want to handle OnLButtonDown when I click on the slider thumb. Anybody have any idea where is the issue.? Any help will be appreciated. Regards, Mbatra
Do you really need a OnLButtonDown on a Slider control? If you just want to handle whenever its value get changed, you can try OnHScroll or OnVScroll instead.
-
Do you really need a OnLButtonDown on a Slider control? If you just want to handle whenever its value get changed, you can try OnHScroll or OnVScroll instead.
Hi, Yes I do need to handle OnLButtonDown. Scenario is I am using slider control to show the progress of the video. Slider will be incremented in steps in proportion to the time elapsed for the video. Now when I click on the slider and hold for the moment, I need to stop it, otherwise the slider keeps incrementing with the timer while still user is holding the mouse on clicking on its thumb. So I need to handle this message handler. I have tried in OnHScroll also, it didn't work. Regards, Mbatra
-
Hi, Yes I do need to handle OnLButtonDown. Scenario is I am using slider control to show the progress of the video. Slider will be incremented in steps in proportion to the time elapsed for the video. Now when I click on the slider and hold for the moment, I need to stop it, otherwise the slider keeps incrementing with the timer while still user is holding the mouse on clicking on its thumb. So I need to handle this message handler. I have tried in OnHScroll also, it didn't work. Regards, Mbatra
In the OnHScroll, the
UINT nSBCode
parameter contains the code message.nSBCode == TB_THUMBTRACK
when you use the mouse to drag it. -
In the OnHScroll, the
UINT nSBCode
parameter contains the code message.nSBCode == TB_THUMBTRACK
when you use the mouse to drag it.I had already tried this......NOT WORKING. just check the same case.....Click on the slider thumb, but don't move the slider. Just click the left button and hold. Slider thumb keeps on moving with the timer and video progression. I need to left click the mouse button on the slider thumb and handle that message. Regards, Mbatra
-
I had already tried this......NOT WORKING. just check the same case.....Click on the slider thumb, but don't move the slider. Just click the left button and hold. Slider thumb keeps on moving with the timer and video progression. I need to left click the mouse button on the slider thumb and handle that message. Regards, Mbatra
I just tried and I get notifications of each move. Code excerpt looks like:
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_NOTIFY(TRBN_THUMBPOSCHANGING, IDC_SLIDER1, &CTestDlg::OnTRBNThumbPosChangingSlider1)
END_MESSAGE_MAP()void CTestDlg::OnTRBNThumbPosChangingSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
NMTRBTHUMBPOSCHANGING *pNMTPC = reinterpret_cast(pNMHDR);TRACE(\_T("Position = %lu\\n"), pNMTPC->dwPos); \*pResult = 0;
}
Did you remember to turn on the "Notify Before Move" style?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
I just tried and I get notifications of each move. Code excerpt looks like:
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_NOTIFY(TRBN_THUMBPOSCHANGING, IDC_SLIDER1, &CTestDlg::OnTRBNThumbPosChangingSlider1)
END_MESSAGE_MAP()void CTestDlg::OnTRBNThumbPosChangingSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
NMTRBTHUMBPOSCHANGING *pNMTPC = reinterpret_cast(pNMHDR);TRACE(\_T("Position = %lu\\n"), pNMTPC->dwPos); \*pResult = 0;
}
Did you remember to turn on the "Notify Before Move" style?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
Hi David, Thanx for the reply. Also plz help me to solve one more issue. I want to to move the thumb where user has clicked the mouse, not in ticks. Slider thumb should move to the position in one shot, user clicked the mouse... I tried this code.....but it didn't work for me.
CRect rc, trc;
m_Slider.GetChannelRect(rc);
m_Slider.GetThumbRect(trc);
rc.InflateRect(0, (trc.Height() - rc.Height())/2);
if (!PtInRect(rc, point))
return;
LONG range = m_Slider.GetRangeMax();
LONG pos = point.x - rc.left - trc.Width()/2;
LONG width = rc.Width() - trc.Width();
m_Slider.SetPos(int(DOUBLE(pos) * range / width + 0.5));Please share any sample code if you have. Regards, Mbatra
-
Hi David, Thanx for the reply. Also plz help me to solve one more issue. I want to to move the thumb where user has clicked the mouse, not in ticks. Slider thumb should move to the position in one shot, user clicked the mouse... I tried this code.....but it didn't work for me.
CRect rc, trc;
m_Slider.GetChannelRect(rc);
m_Slider.GetThumbRect(trc);
rc.InflateRect(0, (trc.Height() - rc.Height())/2);
if (!PtInRect(rc, point))
return;
LONG range = m_Slider.GetRangeMax();
LONG pos = point.x - rc.left - trc.Width()/2;
LONG width = rc.Width() - trc.Width();
m_Slider.SetPos(int(DOUBLE(pos) * range / width + 0.5));Please share any sample code if you have. Regards, Mbatra
Try something like:
void CSliderCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
CSliderCtrl::OnLButtonDown(nFlags, point);CRect rectClient; GetClientRect(rectClient); CRect rectChannel; GetChannelRect(rectChannel); int nPos = (GetRangeMax() - GetRangeMin()) \* (point.x - rectClient.left - rectChannel.left) / (rectChannel.right - rectChannel.left); SetPos(nPos);
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
-
Try something like:
void CSliderCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
CSliderCtrl::OnLButtonDown(nFlags, point);CRect rectClient; GetClientRect(rectClient); CRect rectChannel; GetChannelRect(rectChannel); int nPos = (GetRangeMax() - GetRangeMin()) \* (point.x - rectClient.left - rectChannel.left) / (rectChannel.right - rectChannel.left); SetPos(nPos);
}
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
Hi David, I tried this one also....Still not working. I had one issue, I don't know but the OnLButtonDown() handler is not getting called anymore. This is happening in case of mine. That's why I was not able to set the position of the slider. I have done like this:
void CCapturePage::OnLButtonDown(UINT nFlags, CPoint point)
{
//CSliderCtrl::OnLButtonDown(nFlags, point);
CRect rectClient;
GetClientRect(rectClient);CRect rectChannel; m\_CaptureSlider.GetChannelRect(rectChannel); int nPos = (m\_CaptureSlider.GetRangeMax() - m\_CaptureSlider.GetRangeMin()) \* (point.x - rectClient.left - rectChannel.left) / (rectChannel.right - rectChannel.left); m\_CaptureSlider.SetPos(nPos); //SetCapture(); //SetFocus(); //LBtnValue = m\_CaptureSlider.GetPos(); /\*{ CRect rc, trc; m\_CaptureSlider.GetChannelRect(rc); m\_CaptureSlider.GetThumbRect(trc); rc.InflateRect(0, (trc.Height() - rc.Height())/2); if (!PtInRect(rc, point)) return; LONG range = m\_CaptureSlider.GetRangeMax(); LONG pos = point.x - rc.left - trc.Width()/2; LONG width = rc.Width() - trc.Width(); m\_CaptureSlider.SetPos(int(DOUBLE(pos) \* range / width + 0.5)); }\*/ CPropertyPage::OnLButtonDown(nFlags, point);
}
This is a Propery page which is included in a property sheet. On that Dialog box, I am using a slider control. Does SetCapture() and SetFocus() make any difference in OnLButtonDown(). I don't know why this handler is not getting called.? Regards, Mbatra
-
Hi David, I tried this one also....Still not working. I had one issue, I don't know but the OnLButtonDown() handler is not getting called anymore. This is happening in case of mine. That's why I was not able to set the position of the slider. I have done like this:
void CCapturePage::OnLButtonDown(UINT nFlags, CPoint point)
{
//CSliderCtrl::OnLButtonDown(nFlags, point);
CRect rectClient;
GetClientRect(rectClient);CRect rectChannel; m\_CaptureSlider.GetChannelRect(rectChannel); int nPos = (m\_CaptureSlider.GetRangeMax() - m\_CaptureSlider.GetRangeMin()) \* (point.x - rectClient.left - rectChannel.left) / (rectChannel.right - rectChannel.left); m\_CaptureSlider.SetPos(nPos); //SetCapture(); //SetFocus(); //LBtnValue = m\_CaptureSlider.GetPos(); /\*{ CRect rc, trc; m\_CaptureSlider.GetChannelRect(rc); m\_CaptureSlider.GetThumbRect(trc); rc.InflateRect(0, (trc.Height() - rc.Height())/2); if (!PtInRect(rc, point)) return; LONG range = m\_CaptureSlider.GetRangeMax(); LONG pos = point.x - rc.left - trc.Width()/2; LONG width = rc.Width() - trc.Width(); m\_CaptureSlider.SetPos(int(DOUBLE(pos) \* range / width + 0.5)); }\*/ CPropertyPage::OnLButtonDown(nFlags, point);
}
This is a Propery page which is included in a property sheet. On that Dialog box, I am using a slider control. Does SetCapture() and SetFocus() make any difference in OnLButtonDown(). I don't know why this handler is not getting called.? Regards, Mbatra
mbatra31 wrote:
I had one issue, I don't know but the OnLButtonDown() handler is not getting called anymore.
Because it is supposed to be in a
CSliderCtrl
-derived class."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous