Histogram control | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 5, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.