IE Advanced Options-like Tree View


Application Security Testing: An Integral Part of DevOps

.(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.

  • You must have javascript enabled in order to post comments.

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

Top White Papers and Webcasts

  • A CRM solution holds a wealth of information and document generation tools allow users to take that information and create documents with both visual appeal and function. Document generation is the process of automatically producing a file and document generation applications save companies time, mistakes, and money. You bought Salesforce to be more efficient — why are you still manually creating proposals, contracts, invoices, and account plans? Read this eBook to learn how you can automate virtually …

  • Discover the best practices from HPE’s IT Advisory Consulting Services for migrating and transforming applications in Hybrid IT by capitalizing on innovative platforms, modern application architectures, agile development tools and proven methodologies. There are a number of challenges our customers face when migrating and transforming applications for a Hybrid IT environment. This guide provide proven strategies and application approaches that can help them understand and reduce risks and complexity.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.