Creating a slide control at runtime

Hi can anyone see why there is no CSliderCtrl control being displayed in my dialog at runtime here is my code below
There should be 8 slider controls being displayed
BOOL ColorControl::OnInitDialog()
{
      CPropertyPage::OnInitDialog();

      // TODO:  Add extra initialization here
      
        int sliderTop = 22;
            int SliderBottom = 10;
          for(int i=0;i<m_BOARDCONTROL.chcount;i++){
            if(i<1){
          SetRect(&rcSlider,49,22,110,10);
            }else{
            sliderTop=sliderTop+22;
            SliderBottom=SliderBottom+10;
            SetRect(&rcSlider,49,sliderTop,110,SliderBottom);
            }

      m_Slider.Create(WS_CHILD | WS_VISIBLE | TBS_BOTH | TBS_NOTICKS | WS_TABSTOP ,rcSlider, this, 1);
      m_Slider.ShowWindow(SW_SHOW);
      }
      return TRUE;  // return TRUE unless you set the focus to a control
      // EXCEPTION: OCX Property Pages should return FALSE
}

Open in new window

nchannonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
Have you single stepped into the code to see what code is executing?
Does the m_Slider.Create(... return 0 to indicate success ?

Also the setting TBS_BOTH | TBS_NOTICKS is wierd.  That says display no ticks AND display ticks on both sides of the control - try removing the setting you don't require, it may be upsetting the create call with a request like that.
0
ZoppoCommented:
Hi nchannon,

what is the result when running the ocde? Do you see anything? Do you recieve an error/assertion?

IMO it could be a problem to reuse 'm_Slider' due to MFC internal mechanisms - at least I would guess (I didn't test it) that creating the second slider control may destroy the first created and attached to 'm_Slider' a.s.o.

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
Good point by Zoppo (which I didn't see) - that reuse of m_Slider should result in only one slider control.  But as you don't see any I guess you have another problem as well.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

nchannonAuthor Commented:
Thanks for your comments I change my code to the following and now it works. Andy the return value if the object is created returns 1 and 0 if it fails but great at least I new the object was being created.
Thanks Zoppo with your observation of m_Slider I changed this to an array m_Slider[8] also changed the CRect values and now it all works
BOOL rs;
	    int sliderTop = 20;
		int SliderBottom = 50;
	    for(int i=0;i<m_BOARDCONTROL.chcount;i++){
		if(i<1){
	    SetRect(&rcSlider[i],15,20,220,50);
		}else{
		sliderTop=sliderTop+31;
		SliderBottom=SliderBottom+31;
		SetRect(&rcSlider[i],15,sliderTop,220,SliderBottom);
		}

	    rs=m_Slider[i].Create(WS_CHILD | WS_VISIBLE | TBS_HORZ | TBS_TOP | TBS_AUTOTICKS | TBS_ENABLESELRANGE ,rcSlider[i], this, i+1);
	    m_Slider[i].ShowWindow(SW_SHOW);
	}

Open in new window

0
AndyAinscowFreelance programmer / ConsultantCommented:
You don't actually require separate rectangles for the controls, that can safely be reused
0
nchannonAuthor Commented:
hi Andy not quite sure what you mean by I dont require the separate rectangles for each control.
To my understanding I need to position each control array so they are not positioned on top of each other mybe you could explane a little better so I can try what you mean
0
AndyAinscowFreelance programmer / ConsultantCommented:
&rcSlider[i] - no need for an array to store the rectangles
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.