Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. OnLButtonDown not getting called for Slider Control in MFC.?

OnLButtonDown not getting called for Slider Control in MFC.?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbatra31
    wrote on last edited by
    #1

    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

    T 1 Reply Last reply
    0
    • M mbatra31

      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

      T Offline
      T Offline
      thanh_bkhn
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • T thanh_bkhn

        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.

        M Offline
        M Offline
        mbatra31
        wrote on last edited by
        #3

        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

        T 1 Reply Last reply
        0
        • M mbatra31

          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

          T Offline
          T Offline
          thanh_bkhn
          wrote on last edited by
          #4

          In the OnHScroll, the UINT nSBCode parameter contains the code message. nSBCode == TB_THUMBTRACK when you use the mouse to drag it.

          M 1 Reply Last reply
          0
          • T thanh_bkhn

            In the OnHScroll, the UINT nSBCode parameter contains the code message. nSBCode == TB_THUMBTRACK when you use the mouse to drag it.

            M Offline
            M Offline
            mbatra31
            wrote on last edited by
            #5

            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

            D 1 Reply Last reply
            0
            • M mbatra31

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              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

              M 1 Reply Last reply
              0
              • D David Crow

                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

                M Offline
                M Offline
                mbatra31
                wrote on last edited by
                #7

                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

                D 1 Reply Last reply
                0
                • M mbatra31

                  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

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  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

                  M 1 Reply Last reply
                  0
                  • D David Crow

                    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

                    M Offline
                    M Offline
                    mbatra31
                    wrote on last edited by
                    #9

                    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

                    D 1 Reply Last reply
                    0
                    • M mbatra31

                      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

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups