Figure 1: Visual InterDev 6 Option Dialog
OverviewMany of Microsoft's development products are beginning to go away from the tabbed dialog metaphor and have started using a single dialog with a treeview control that is used to display application options in a hierarchical fashion. Figure 1 (above) shows the Options dialog in Visual InterDev 6, but other development products, such as the new Visual Studio.NET are also following suit.
Therefore, in order to make this new UI a little bit easier, I have created a new class called COptionsTree. Using this class is extremely easy and requires only the following steps:
- Place a tree control on the dialog
- Place the different controls on the dialog that will constitute your options. Make sure and turn the Visible property off for each of these controls.
- Declare a member variable of type COptionsTree in the dialog class
- In the dialog's OnInitDialog member function, call SubClasDlgItem with the resource id of the tree control. This will allow my class to subclass the tree control.
- Use COptionsTree::AddControl member function to associate each control with a specific tree item. There's an example of how to do this below.
Example Source CodeIncluded with this article is a demo that when run looks like the following:
Figure 2: Demo application - notice how the controls automatically display/hide based on which item in the treeview control is selected.
// subclass the treeview with the COptionsTree class m_Tree.SubclassDlgItem(IDC_TREE,this); HTREEITEM hItem, hParentItem; // insert the first item and get it's HTREEITEM hParentItem = m_Tree.InsertItem("First"); // use the HTREEITEM to associate each control with a given tree item m_Tree.AddControl(hParentItem, GetDlgItem(IDC_RADIO)); m_Tree.AddControl(hParentItem, GetDlgItem(IDC_FIRST_STATIC)); // insert the second item (in this example, it's a child of the first hItem = m_Tree.InsertItem("Second",hParentItem); // use the HTREEITEM to associate each control with a given tree item m_Tree.AddControl(hItem,GetDlgItem(IDC_COMBO)); m_Tree.AddControl(hItem,GetDlgItem(IDC_CHECK)); m_Tree.AddControl(hItem, GetDlgItem(IDC_SECOND_STATIC));
DownloadsDownload demo project 17 Kb
Download source 3 Kb