IE Advanced Options-like Tree View

.(Beijing, P.R.China)

When I am programming, I find a boring work is to implement many options. Normally I have to do the following works:

1.Declare many variants to identify the options.
2.Implement user interface to set the options.
3.Load the value from registry for each option.
4.Save the value to registry for each option.

I had to write lots of codes to do the work and the codes looks like the same. so I build two classes to implement the works in a simple way.

The class COption hold all the options, and the class COptionsTreeCtrl will supply a TreeCtrl to show and modify the options. e.g.

There are two type of options: Radio and Check. To a Radio option, it can be set to the value of 0, 1, ..., to a Check Option, it can be set to the value of COptions::CheckTrue(-1) or COptions::CheckFalse(0).

Each option can have three appearence properties: text ,true image and false image. the properties will be used in COptionsTreeCtrl to show the option item.

There are two functions to load and save all the options from the registry.


1.Declare a member of COptions to hold all options in your porgram.

COptions m_Options;

2.Initialize a option in the member.

m_Options.SetOption("RadioOption1", 0);

The string "RadioOption1" is the identifier, and will be used in two way:
a)Get the option value:


b)As the key string when save it in registry.
The second parameter is the default value, before loading from registry, the option will be the value of second parameter. To a Check Option, it can be COptions::CheckTrue or COptions::CheckFalse. To a Radio Option, it can be 0, 1, ...

3.Initialize a option appearence in the COptionTreeCtrl.

m_Options.SetOptionItem("RadioOption1", "\tSelection 0", 0, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOptionItem("RadioOption1", "\tSelection 1", 1, IDB_RADIOON, IDB_RADIOOFF);

a)The first parameter is the ID of the Option.
b)the second parameter is the text which will be shown in the tree. the char '\t' is the indent mark, one '\t' means the item will be child of the root. and two '\t' ('\t\t') means the item will be the child of the child of the root. Normally before the '\t\t' item, there must be a '\t' item, and so on.
c)the third parameter is the true value of this item. A Radio option normally has many selections, one selection should have a appearence, so one selection should have a code line like the forgoing. each line will have its own true value. When the value of the option equal to the true value of this line, the Image of the item in the COptionsTreeCtrl will be the bitmap resource identified by parameter fourth, otherwise, the item will be shown in bitmap resource identified by the fifth parameter.
d)To Initialize a item which doesn't been associated with a option, (e.g. the first line in the front picture) you can use the following line:

m_Options.SetOptionItem("Radio Options", IDB_ITEMS, IDB_ITEMS);

The parameters are the ID ,image, selected image.

4.Load and save.


The two functions will load or save all the options in the class COption, each option will use the ID as its key name.The parameter is the section name of all options.

5.Show and Modify.
The Options can be shown in a COptionsTreeCtrl and modified automaticly when click the image of a item/Option.
The following is a sample. A COptionsTreeCtrl is placed in a dialog(COptionsDlg):

COptionsDlg dlg;
dlg.m_OptionsTreeCtrl.m_pOptions = &m_Options;
if (dlg.DoModal() == IDOK)

In the COptionsDlg Initialize Message handler, you must add the following line:


The item text in the COptionsTreeCtrl equal to the string in the parameter will be expanded. Null to expand all the items in the COptionsTreeCtrl.

The options in the front picture will be generated by the following codes:

m_Options.SetOption("RadioOption1", 0);
m_Options.SetOption("RadioOption2", 1);
m_Options.SetOptionItem("Radio Options", IDB_ITEMS, IDB_ITEMS);
m_Options.SetOptionItem("RadioOption1", "\tSelection 0", 0, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOptionItem("RadioOption1", "\tSelection 1", 1, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOptionItem("RadioOption1", "\tSelection 2", 2, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOptionItem("RadioOption2", "\t\tSelection 0", 0, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOptionItem("RadioOption2", "\t\tSelection 1", 1, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOptionItem("RadioOption1", "\tSelection 3", 3, IDB_RADIOON, IDB_RADIOOFF);

m_Options.SetOptionItem("Check Options", IDB_ITEMS, IDB_ITEMS);
m_Options.SetOption("CheckOption1", COptions::CheckFalse);
m_Options.SetOptionItem("CheckOption1", "\tCheck 1", COptions::CheckTrue, IDB_CHECKON, IDB_CHECKOFF);
m_Options.SetOption("RadioOption3", 1);
m_Options.SetOptionItem("RadioOption3", "\t\tSelection 0", 0, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOptionItem("RadioOption3", "\t\tSelection 1", 1, IDB_RADIOON, IDB_RADIOOFF);
m_Options.SetOption("CheckOption2", COptions::CheckTrue);
m_Options.SetOptionItem("CheckOption2", "\tCheck 2", COptions::CheckTrue, IDB_CHECKON, IDB_CHECKOFF);


Download demo project - 36 Kb
Download source - 6 Kb


  • Thanks

    Posted by Legacy on 12/06/2001 12:00am

    Originally posted by: Hakan Toktas

    Very useful classes,

    Thanks for sharing your work with us.

  • Suggested additions - int values

    Posted by Legacy on 09/25/2000 12:00am

    Originally posted by: Brian Price

    Excellent control - exactly what I was looking for, but for one small thing. Any ideas how to add an int value rather than checkbox or radio button ? It would then be perfect :)

  • Great classes!

    Posted by Legacy on 04/06/2000 12:00am

    Originally posted by: Andrew Galland

    Thanks a lot. This is a really helpful post, and has saved me lots of time and hassle.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Microsoft® Office 365 is a top choice for enterprises that want a cloud–based suite of productivity collaboration applications. With Office 365, you get access to Microsoft™ Office solutions practically anytime, anywhere, on virtually any device. It's a great option for current Microsoft users who can now build on their experience with Microsoft™ solutions while enjoying the flexibility of a cloud-based delivery. But even organizations with no previous investment in Microsoft will find that …

  • For many organizations, moving enterprise applications to the public cloud can be a very attractive proposition, but planning the best way to move your applications is mission–critical. As an alternative to the costly option of re–architecting the application for a cloud environment, you can follow a "lift and shift" model that's significantly cheaper and almost always a lot quicker. In order to have a successful "lift and shift" migration, read this white paper to learn a few rules you should …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date