CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2005
    Posts
    119

    [RESOLVED] working with slider bar

    I've got an MFC app that uses afx messaging.

    I have a slider whose position I monitor using the OnHScroll function. It works...too well
    As soon as I click on the slider, it enters the OnHScroll function. I don't get a chance to move it my desired new position. What I want is to be able to grab the slider with the mouse, move it to a new position, release the mouse, and have the function retreive this final position.

    Is there a neat & simple way to modify my code below to do this ?

    Code:
    void TestDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
    {
    	int x;
    
    	x= m_Slider.GetPos();
    
        // do some stuff with x
       
     }
    m_Slider is of type CSliderCtrl.
    My message map contains ON_WM_SCROLL.

    Thanks,
    ak

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: working with slider bar

    Are you checking the nSBCode that's getting passed to your handler? Look for the value SB_ENDSCROLL.

  3. #3
    Join Date
    Apr 2005
    Posts
    119

    Re: working with slider bar

    Thanks - that works !
    I just used an if(nSBCode == SB_ENDSCROLL) statement to only perform my operations when SB_ENDSCROLL has been flagged.

    One more minor issue -

    When I start my application I want the slider bar to start off in position 4. Here's my initialization function :

    Code:
    BOOL TestDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Add "About..." menu item to system menu....
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		CString strAboutMenu;
    		strAboutMenu.LoadString(IDS_ABOUTBOX);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// Set the icon for this dialog...
    
    	m_Slider.SetPos(4);                 // setting the initial slider position
    	m_Slider.SetRange(0,7);
    
        // other control settings ...
    
        UpdateData(FALSE);
    
    	return TRUE;
    }
    But instead it starts off elsewhere like 0 & as soon as I click the slider with the mouse it hops over to position 4.

    How can I make it start at 4 without having to click on the control ?

    ak

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: working with slider bar

    Quote Originally Posted by rowgram View Post
    Thanks - that works !
    I just used an if(nSBCode == SB_ENDSCROLL) statement to only perform my operations when SB_ENDSCROLL has been flagged.

    One more minor issue -

    When I start my application I want the slider bar to start off in position 4. Here's my initialization function :

    Code:
    BOOL TestDlg::OnInitDialog()
    {
    	CDialog::OnInitDialog();
    
    	// Add "About..." menu item to system menu....
    
    	CMenu* pSysMenu = GetSystemMenu(FALSE);
    	if (pSysMenu != NULL)
    	{
    		CString strAboutMenu;
    		strAboutMenu.LoadString(IDS_ABOUTBOX);
    		if (!strAboutMenu.IsEmpty())
    		{
    			pSysMenu->AppendMenu(MF_SEPARATOR);
    			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    		}
    	}
    
    	// Set the icon for this dialog...
    
    	m_Slider.SetPos(4);                 // setting the initial slider position
    	m_Slider.SetRange(0,7);
    
        // other control settings ...
    
        UpdateData(FALSE);
    
    	return TRUE;
    }
    But instead it starts off elsewhere like 0 & as soon as I click the slider with the mouse it hops over to position 4.

    How can I make it start at 4 without having to click on the control ?

    ak
    Try SetRange first.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured