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.

Usage:

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:

m_Options["RadioOption1"]

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.

m_Options.RegLoad("Settings");
m_Options.RegSave("Settings");

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;
m_Options.BeginTrans();
if (dlg.DoModal() == IDOK)
m_Options.CommitTrans();
else
m_Options.RollbackTrans();

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

m_OptionsTreeCtrl.Initialize(NULL);

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.

6.Sample:
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);

Downloads

Download demo project - 36 Kb
Download source - 6 Kb


Comments

  • 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=http://www.nikejapan.asia/]ナイキ エア[/url] Specifically how to learn anything and everything there is to find related to nike shoes in six easy steps. [url=http://www.adidasjapan.biz/]アディダス シューズ[/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=http://www.guccijp.asia/]財布 gucci[/url] An ideal method for the chloe that you may understand more about right away. [url=http://www.chloejp.biz/]クロエ 財布[/url] The Amazing chanel Hack May Well Fool Just about all [url=http://www.chaneljp.biz/]シャネル 財布[/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=http://www.adidasjapan.asia/]adidas シューズ[/url] What other people actually does when contemplating nike shoes and consequently the things that youshould do totally different. [url=http://www.nikejp.biz/]スニーカーナイキ[/url] What pros won't be thinking in relation to adidas shoes as well as how this is relevant to you actually.

    Reply
  • 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.

    Reply
  • 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 :)

    Reply
  • 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.

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

Top White Papers and Webcasts

  • With JRebel, developers get to see their code changes immediately, fine-tune their code with incremental changes, debug, explore and deploy their code with ease (both locally and remotely), and ultimately spend more time coding instead of waiting for the dreaded application redeploy to finish. Every time a developer tests a code change it takes minutes to build and deploy the application. JRebel keeps the app server running at all times, so testing is instantaneous and interactive.

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds