Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Creating a slide control at runtime

Posted on 2010-11-08
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()

      // TODO:  Add extra initialization here
        int sliderTop = 22;
            int SliderBottom = 10;
          for(int i=0;i<m_BOARDCONTROL.chcount;i++){

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

Open in new window

Question by:nchannon
  • 4
  • 2
LVL 44

Expert Comment

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.
LVL 31

Accepted Solution

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.

LVL 44

Assisted Solution

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.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

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++){

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

Open in new window

LVL 44

Expert Comment

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

Author Comment

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
LVL 44

Expert Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.

789 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