Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Control Positioner -- Repostion your child windows without code change

0.00/5 (No votes)
24 Jun 2003 1  
This is a small class for control repositioning. It can create an INI file, which logs all aspects of your control.

Sample Image - Control_Positioner.gif

Introduction

Control Positioner (Control Poser) - This is a small class for control repositioning. It can create an INI file, which logs all aspects of your controls (child windows). e.g.:

  1. Enable
  2. Visibility
  3. Default value (checked or text title)
  4. Size and screen position

So when you want to change them, you just update this INI file instead of recompiling your code. Sometimes it helps to create a highly flexible user interface, especially useful when the customer doesn't know what they want or your requirement manager has a really changing personality :-)

How to use it:

  1. Include header CtrlPositioner.h in your Dialog/Main window code.
  2. In OnInitDialog add:
    CCtrlPositioner poser;
     poser.SetDlg(this); 
    //Add the control you wish to control
    
     poser.AddCtrl(IDC_STATIC); 
     poser.AddCtrl(IDC_CHECK1);
     poser.AddCtrl(IDC_EDIT1);
     poser.AddCtrl(IDC_BUTTON1); 
     //poser.SavePosData(); //This creates an ini file for you first time,
    
                           //so latter you can just change the file.
    
                          //This line should be commented 
    
                         //out after you got the file
    
    poser.ReadPosData(); //Read Position from ini file
    
    //Organize control regarding your ini definition.
    
    poser.PositionControls(); 

Notes:

  1. INI file is called CtrlPos.ini, this can be changed easily in CtrlPositioner.cpp.
  2. This class should also work with other parent windows besides CDialog, although I never tested it :-(
  3. Currently parent window's title is used as section name in INI file, it's not good as there could be more windows with the same caption on it. I would like to improve this if you can give me any suggestions?

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here