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.
Last updated: 17 May 1998

Comments
How to setup Histogram code in Visual C++ 6.0
Posted by ringram2077 on 02/14/2007 04:46pmNot having any luck getting Histogram set up in VC++. Could someone layout the steps to get it setup to compile ? Thanks
ReplyAnother GOOD GDI example
Posted by Legacy on 03/10/2003 12:00amOriginally posted by: motty brami
ReplyControl in Task Manager
Posted by Legacy on 12/09/2001 12:00amOriginally posted by: jj
In Window's Task Manager, under the "performance" sheet,
there're two graphs showing the "cpu usage" and "memory usage".
Anyone knows which control can be used to realise this
kind of drawing?
thanks
ReplyGood job!
Posted by Legacy on 11/04/2001 12:00amOriginally posted by: Shiuh Liew
Ken,
You have done a good job. The code is simple, clean, and efficient.
Shiuh
ReplyHow to add code
Posted by Legacy on 08/01/2001 12:00amOriginally posted by: winne
ReplyNeat
Posted by Legacy on 06/07/2001 12:00amOriginally posted by: Chokri Oueslati
It is neat and clear. Very easy to handle.
ReplyHow ot preview and print in a doc/view program?
Posted by Legacy on 05/15/2000 12:00amOriginally posted by: Joshua Liu
I create the control in a view;but it cannot preview and
Replyprint.How should I do?
Thanks very much!
My Email is joshua0137@sina.com
about histogram......
Posted by Legacy on 11/05/1999 12:00amOriginally posted by: abc88
ReplyResizing a Custom Control
Posted by Legacy on 04/17/1999 12:00amOriginally posted by: M. Qureshi
I tried to resize the control as the dialog is resized using the following code but it didn't work.
CMyDialog::OnSize(...)
{
if(m_HistogramCtrl.GetSafeHwnd())
{
CRect rect;
GetClientRect(rect);
m_HistogramCtrl.MoveWindow(rect);
}
I might use this control with little modification if I could resize it.
Reply