Solved

Creating a slide control at runtime

Posted on 2010-11-08
7
542 Views
Last Modified: 2013-11-20
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

0
Comment
Question by:nchannon
  • 4
  • 2
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34090974
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
 
LVL 31

Accepted Solution

by:
Zoppo earned 125 total points
ID: 34090996
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
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 125 total points
ID: 34091011
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:nchannon
ID: 34091519
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34091536
You don't actually require separate rectangles for the controls, that can safely be reused
0
 

Author Comment

by:nchannon
ID: 34092240
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
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34092499
&rcSlider[i] - no need for an array to store the rectangles
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now