CNavigatorCtrl'�A Navigation Control that Allows You to Mark and Set Items Completed

Environment: Visual C++

Here's another control that I wrote (love writing controls!) that most likely no one else will use, but I figured I would contribute it anyway! I wrote it in a day so it does have some limitations. The control is a custom navigation control that allows a user to scroll horizontally through any number of items, selecting them, marking them, and/or setting them as completed. It is not much use on its own, but when combined with a class that needs navigation, it can be quite handy.

Personally, I needed the control for a very specific project, so built-in functionality is somewhat limited and quite basic. Some of these limitations include: no vertical support, set block and font size, and it has not been tested when resizing occurs.

The control, by default, uses the system colors for the items that are painted. Here's what a default one may look like:

The control can also be completely customized to use any set of colors or fonts types that you want. Here's what a customized one may look like:

Using the navagation control is extremely easy. To add the control to your project, simply do the following.

  1. Add the files NavigatorCtrl.cpp and NavigatorCtrl.cpp to your project.
  2. Add the files 'marked.bmp' and 'HAND_T.CUR' to the resources of your project. The marked.bmp image must be called IDD_MARKED and the cursor must be called "HAND_T". You can replace the marked.bmp with an image of your own, but be sure that it is NOT bigger than the one supplied!
  3. Create the control (see below)
  4. Set items' attributes (see below)
  5. Handle the messages (see below)

Step 3. Create the Control

int nItems = 10;
m_pNavigatorCtrl = new CNavigatorCtrl();
m_pNavigatorCtrl->Create(CRect(200,100,460,140), this,
                  ID_CONTROL_ID, nItems
    ,5                   // Block Spacer
    ,false               // Border
    ,RGB(204,214,223)    // Background color
    ,RGB(255,255,255)    // Boxes Background color
    ,RGB(200,255,255)    // Completed Background color
    ,RGB(52,90,129)      // Outline Color
    ,RGB(52,90,129       // Text Color
    ,RGB(0,0,255)        // Completed Text Color
    ,RGB(157,176,194)    // Separator Line Color
    ,"Ms Sans Serif"     // Font face

The first four items in the create are required. The only one that probably needs explaining is the last one—'nItems'. This parameter is the number of items you want the control to start with. All the other parameters set the GUI type of attributes. As you can see, it is quite robust in this area.

Step 4. Set Items' Attributes

You can set an item either Marked, Completed, or both. Here's an example:

int nItemNumber = 3
bool bCompleted = true;
m_pNavigatorCtrl->SetCompleted(nItemNumber, bCompleted);

bool bMarked = true;
m_pNavigatorCtrl->SetMarked(nItemNumber, bMarked);

Step 5. Handle the Control's Messages

The control only sends one message right now: ICM_NAV_ITEMSELECTED.

To add this to your project, add the following Message Map handler in the class that will handle the message:


Then, add the defintition of this handler to the .h file of the same class:

afx_msg LONG OnNavItemSelected(UINT uItemSelected, LONG lUnused);

Then, add the function that will handle the message. This function also shows you how to get values out of an item in the control. As you can see, there are not many functions to call on the control.

LONG CTempView::OnNavItemSelected(UINT uItemSelected, LONG lUnused)
  // Get the Item Selected
  CString csItem;
  csItem.Format("Item %d is ", uItemSelected);

  // Is it marked?
    csItem += "Marked";
    csItem += "NOT Marked";

  // Is it completed?
    csItem += " and is Completed";
    csItem += " and is NOT Completed";

  // Show Message
  return 1;

As stated before, this control has limited functionality in order to meet a crazy timeline! (What else is new, huh?) I'm sure there will be updates in the near future for added functionality, and I will post them ASAP.

Also, because it was written in a day, I'm sure there are bugs (bugs?!?) in it that I have overlooked. As I find them, I will also post updates.

Well, I hope at least one other person also finds some type of use for this control. It was fun to write!


Download demo project - 56 Kb


  • Updates

    Posted by Legacy on 09/23/2003 12:00am

    Originally posted by: Brett Mitchell

    I have added some addional functionality such as reseting the contents, setting the initial current item, etc. If you need an update please email me! :)

  • Nice Job!

    Posted by Legacy on 09/22/2003 12:00am

    Originally posted by: BNEACETP

    Nice Job!

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • With the average hard drive now averaging one terabyte in size, the fallout from the explosion of user-created data has become an overwhelming volume of potential evidence that law-enforcement and corporate investigators spend countless hours examining. Join Us and SANS' Rob Lee for our 45-minute webinar, A Triage and Collection Strategy for Time-Sensitive Investigations, will demonstrate how to: Identify the folders and files that often contain key insights Reduce the time spent sifting through content by …

Most Popular Programming Stories

More for Developers

RSS Feeds