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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CSliderCtrl Range Setting Trouble

CSliderCtrl Range Setting Trouble

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 1 Posters 2 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.
  • J Offline
    J Offline
    Justin Cooke
    wrote on last edited by
    #1

    I'm having trouble using a CSliderCtrl. I'm trying to set the range from 0 -> 16384 by calling: m_sliderZoom.SetRange(0, 16384, FALSE); in the OnInitDialog() func. Two strange things are happening. First, if I immediately call GetRange() on the control, it returns both min and max values as 0. Secondly, when I call GetRange() later in the code, the range is always from 0 -> 100. So, why doesn't GetRange() at least return 0 -> 100 immediately after setting the range? And, more importantly, why am I unable to change the range from 0 -> 100? I've tried setting it to 0 -> 25, as well, with no difference in the final range. Any help is greatly appreciated.:confused: Here's what I think is the relevant code: BOOL CSMRLocatorDlg::OnInitDialog() { // other stuff m_sliderZoom.SetRange(0, 16384, FALSE); int min; int max; m_sliderZoom.GetRange( min, max ); CString message; message.Format( "Min: %d Max: %d", min, max ); AfxMessageBox( message ); // always "Min: 0 Max: 0" // other stuff } // later in the code void CSMRLocatorDlg::OnOut() { m_nZoomLevel = m_sliderZoom.GetPos(); CString message; int min; int max; m_sliderZoom.GetRange( min, max ); message.Format( "Min: %d Max: %d", min, max ); AfxMessageBox( message ); // always "Min: 0 Max: 100" }

    J 1 Reply Last reply
    0
    • J Justin Cooke

      I'm having trouble using a CSliderCtrl. I'm trying to set the range from 0 -> 16384 by calling: m_sliderZoom.SetRange(0, 16384, FALSE); in the OnInitDialog() func. Two strange things are happening. First, if I immediately call GetRange() on the control, it returns both min and max values as 0. Secondly, when I call GetRange() later in the code, the range is always from 0 -> 100. So, why doesn't GetRange() at least return 0 -> 100 immediately after setting the range? And, more importantly, why am I unable to change the range from 0 -> 100? I've tried setting it to 0 -> 25, as well, with no difference in the final range. Any help is greatly appreciated.:confused: Here's what I think is the relevant code: BOOL CSMRLocatorDlg::OnInitDialog() { // other stuff m_sliderZoom.SetRange(0, 16384, FALSE); int min; int max; m_sliderZoom.GetRange( min, max ); CString message; message.Format( "Min: %d Max: %d", min, max ); AfxMessageBox( message ); // always "Min: 0 Max: 0" // other stuff } // later in the code void CSMRLocatorDlg::OnOut() { m_nZoomLevel = m_sliderZoom.GetPos(); CString message; int min; int max; m_sliderZoom.GetRange( min, max ); message.Format( "Min: %d Max: %d", min, max ); AfxMessageBox( message ); // always "Min: 0 Max: 100" }

      J Offline
      J Offline
      Justin Cooke
      wrote on last edited by
      #2

      OK. I figured it out and I'm feeling very stupid right now. The base version of CDialog::OnInitDialog() was being called, but not until after I was trying to SetRange() and GetRange(). This explains the bogus results of GetRange() and the fact that my desired range had no effect. I can offer as an excuse the fact that I was handed this code after somebody else wrote it:-D I am still wondering how this code worked before, though. According to the previous developer, he had no problems setting the range, even with the call coming before CDialog::OnInitDialog(). Does anyone know if different platforms or versions of MFC DLLs or something else could have allowed the code to work this way? Thanks.

      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