Click here to Skip to main content
15,889,527 members
Articles / Desktop Programming / MFC
Article

Control Positioner -- Repostion your child windows without code change

Rate me:
Please Sign up or sign in to vote.
3.00/5 (7 votes)
24 Jun 2003 77.7K   1.9K   28   7
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


Written By
Software Developer (Senior) www.wonga.com
Ireland Ireland
I have over 13 Years IT industry experience as Principle/Senior Programmer. I am experienced in .NET/J2EE system design and detailed implementation. I master UML modelling and OO design methodology with a strong C#/C++/Java coding background. I have been in working/managing a distributed project using Agile/Waterfall approach. My business knowledge includes Telecommunication, Financial Investment/Trading, and Banking.

Comments and Discussions

 
Questionideas? Pin
andyj11525-Jun-03 4:46
andyj11525-Jun-03 4:46 
AnswerRe: ideas? Pin
Ziming25-Jun-03 4:55
Ziming25-Jun-03 4:55 
GeneralRe: ideas? Pin
TW25-Jun-03 5:50
TW25-Jun-03 5:50 
GeneralRe: ideas? Pin
Ziming25-Jun-03 6:00
Ziming25-Jun-03 6:00 
GeneralRe: ideas? Pin
TW26-Jun-03 0:36
TW26-Jun-03 0:36 
GeneralRe: ideas? Pin
andyj11525-Jun-03 7:45
andyj11525-Jun-03 7:45 
GeneralRe: ideas? Pin
Ziming25-Jun-03 21:59
Ziming25-Jun-03 21:59 
Hi,

The idea of using resource ID is exactly what I was thinking initially. I believe it should work fine with your situation. But I still will not recommend you to use such kinda class for all the controls in your window, because you may find it a mess and failed to save your time at last.

XML is good staff to use, but I don't like MSXML because it's too big for a small project, that's why I use Expat (A light lib) more often or completely avoid it.

Thank you for your input. I did not realise I can meet so many good developer here.

Ziming WangBlush | :O

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.