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


  • Drop Whining And Initiate your personal nike shoes Project Instead

    Posted by expopmerm on 03/18/2013 01:54am

    Short article discloses the incontestable information regarding adidas shoes and how it may cause problems for users.|Extra short article helps you with all details of the nike shoes combined with the actions you must do right now.}[url=]ナイキ エア[/url] Specifically how to learn anything and everything there is to find related to nike shoes in six easy steps. [url=]アディダス シューズ[/url] adidas shoes can provide all new lifespan to an old problem. . . defacto conventional The Secret Of Methods One Can Master gucci Devoid Of Any Past experiences! [url=]財布 gucci[/url] An ideal method for the chloe that you may understand more about right away. [url=]クロエ 財布[/url] The Amazing chanel Hack May Well Fool Just about all [url=]シャネル 財布[/url] Ways to learn just about every thing there is to understand concerning chanel in four easy steps.The Lad who ended up selling his adidas shoes report for one million [url=]adidas シューズ[/url] What other people actually does when contemplating nike shoes and consequently the things that youshould do totally different. [url=]スニーカーナイキ[/url] What pros won't be thinking in relation to adidas shoes as well as how this is relevant to you actually.

  • 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

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

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