Microsoft Development Environment-Like Options Dialog Class


Figure 1: Visual InterDev 6 Option Dialog

Overview

Many 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:

  1. Place a tree control on the dialog
  2. 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.
  3. Declare a member variable of type COptionsTree in the dialog class
  4. 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.
  5. 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 Code

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

In this demo, we have a dialog with two options (First and Second). The First option is associated with a static control and a radio button. The Second option is associated with a static control, a check box and a combo box. Below is all the code needed to make this work.
// 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));

Downloads

Download demo project 17 Kb
Download source 3 Kb


Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: November 13, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT APIs can be a great source of competitive advantage. The practice of exposing backend services as APIs has become pervasive, however their use varies widely across companies and industries. Some companies leverage APIs to create internal, operational and development efficiencies, while others use them to drive ancillary revenue channels. Many companies successfully support both public and private programs from the same API by varying levels …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds