-
June 20th, 2013, 12:07 PM
#1
OnLButtonDown not getting called on 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, instead 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
-
June 20th, 2013, 12:17 PM
#2
Re: OnLButtonDown not getting called on Slider control in MFC.?
I think that you should handle WM_HSCROLL (for horizontal slider) and
WM_VSCROLL for a vertical slider.
-
June 20th, 2013, 03:13 PM
#3
Re: OnLButtonDown not getting called on Slider control in MFC.?
Originally Posted by Mbatra
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, instead 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.?
I am sure that MSDN has an idea!
And I wonder why you ignore it! Just read about Slider Notification Messages
Victor Nijegorodov
-
June 21st, 2013, 02:13 AM
#4
Re: OnLButtonDown not getting called on Slider control in MFC.?
Code:
// SliderCtrlEx.h
#pragma once
// CSliderCtrlEx
class CSliderCtrlEx : public CSliderCtrl
{
DECLARE_DYNAMIC(CSliderCtrlEx)
public:
CSliderCtrlEx();
virtual ~CSliderCtrlEx();
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
};
Code:
// SliderCtrlEx.cpp : implementation file
//
#include "stdafx.h"
#include "TcForge.h"
#include "SliderCtrlEx.h"
#include ".\sliderctrlex.h"
// CSliderCtrlEx
IMPLEMENT_DYNAMIC(CSliderCtrlEx, CSliderCtrl)
CSliderCtrlEx::CSliderCtrlEx()
{
}
CSliderCtrlEx::~CSliderCtrlEx()
{
}
BEGIN_MESSAGE_MAP(CSliderCtrlEx, CSliderCtrl)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
// CSliderCtrlEx message handlers
void CSliderCtrlEx::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect rc, trc;
GetChannelRect(rc);
GetThumbRect(trc);
rc.InflateRect(0, (trc.Height() - rc.Height())/2);
if (!PtInRect(rc, point))
return;
LONG range = GetRangeMax();
LONG pos = point.x - rc.left - trc.Width()/2;
LONG width = rc.Width() - trc.Width();
SetPos(int(DOUBLE(pos) * range / width + 0.5));
CSliderCtrl::OnLButtonDown(nFlags, point);
}
Best regards,
Igor
-
June 21st, 2013, 03:50 AM
#5
Re: OnLButtonDown not getting called on Slider control in MFC.?
Hi,
I had already tried this .
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, but 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.
I am moving the slider control in progress with the video. When I click on the slider thumb and hold the mouse button there, cursor remains there but slider thumb moves ahead. I need to handle this in OnLButtonDown when I click the slider thumb. But OnLButtonDown handler doesn't get called either.
Regards,
Mbatra
-
June 21st, 2013, 11:18 AM
#6
Re: OnLButtonDown not getting called on Slider control in MFC.?
The code I provided is a part of another application that really works okay. And before sending the code I definitely made sure OnLButtonDown handler gets called when I press mouse button on slider thumb. So the click event fires alright, and the handler gets called.
The fact that you're somehow not able to handle the event indicates that your understanding of reasons and consequences does not match the reality. You either refresh your understanding yourself, or post some compilable sample here that replicates the trouble you have.
Best regards,
Igor
-
June 21st, 2013, 12:06 PM
#7
Re: OnLButtonDown not getting called on Slider control in MFC.?
Originally Posted by Mbatra
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, but the slider keeps incrementing with the timer while still user is holding the mouse on clicking on its thumb.
When you get a left button down message, you need to stop incrementing the slider. When you get a lbuttonup message, reenable the stepping.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|