Histogram control

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.

Important

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
protected:
CHistogramCtrl m_HistogramCtrl;

};

And in the initial dialog box…


BOOL CHistogramTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();

CRect rect;
GetDlgItem(IDC_STATIC_HISTOGRAM)->GetWindowRect(rect);
ScreenToClient(rect);

m_HistogramCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this, 100);
m_HistogramCtrl.SetRange(0,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
[email protected] 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

More by Author

Must Read