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

  • At present, the most commonly deployed parallel file system is Lustre, and its adoption is growing across the HPC industry. According to Intersect 360 Research, "Through its leadership and involvement with OpenSFS, Cray advocates for the development of features that drive efficient performance at scale." Moreover, with help from Cray and OpenSFS, Lustre is gaining greater adoption across broader commercial application categories. As data and I/O requirements grow in commercial markets, technology vendors -- …

  • The 2014 State of DevOps Report — based on a survey of 9,200+ people in IT operations, software development and technology management roles in 110 countries — reveals: Companies with high-performing IT organizations are twice as likely to exceed their profitability, market share and productivity goals. IT performance improves with DevOps maturity, and strongly correlates with well-known DevOps practices. Job satisfaction is the No. 1 predictor of performance against organizational …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date