Histogram control


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

histogram control  Download Source Code and Example

This custom control displays a left scrolling spike with range configurable by calling SetRange(0,100), the first parameter is the min(bottom) value and the second parameter is max(top) value.

The control is designed to work just like the progress control but with a twist. Every SetPos() will shows a spike and the next SetPos() will scroll the previous one to the left.

The CHistogramCtrl class is derived from CWnd, the header and code are in HistogramCtrl.h and HistogramCtrl.cpp files.


In your dialog box, you must create the control as static control (use "picture" from control toolbar). You must set the properties to

  • Type: Rectangle, and
  • Color: black. (I think black background looks better)

Don't worry about the height, width and border, the control will ajust itself and draw the border for you.

First add a member to your dialog class like this:

class CHistogramTestDlg : public CDialog
// Implementation
	CHistogramCtrl m_HistogramCtrl;

And in the initial dialog box...

BOOL CHistogramTestDlg::OnInitDialog()

	CRect rect;

	m_HistogramCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this, 100);
	return TRUE;  // return TRUE  unless you set the focus to a control

And the rest use SetPos(UINT nValue).

The custom control uses unique painting technique which is a little bit to long to discuss here. If you want to understand more please email your FAQ to klen@bellatlantic.net thanks. (The code is not as long to read)

Here is an example of how an application looks like with the control.

histogram control

Last updated: 17 May 1998

This article was originally published on August 5th, 1998

Most Popular Programming Stories

More for Developers

RSS Feeds

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