OnLButtonDown not getting called on Slider control in MFC.?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: OnLButtonDown not getting called on Slider control in MFC.?

  1. #1
    Join Date
    Nov 2009
    Posts
    24

    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

  2. #2
    Join Date
    Aug 2000
    Location
    West Virginia
    Posts
    7,564

    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.

  3. #3
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,273

    Re: OnLButtonDown not getting called on Slider control in MFC.?

    Quote Originally Posted by Mbatra View Post
    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

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,925

    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

  5. #5
    Join Date
    Nov 2009
    Posts
    24

    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

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,925

    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

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,197

    Re: OnLButtonDown not getting called on Slider control in MFC.?

    Quote Originally Posted by Mbatra View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center