Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

COscilloscopeCtrl

0.00/5 (No votes)
14 Mar 2003 1  
An oscilloscope control with multiple band(frequency) support

Introduction

Recently, one of the projects that I'm working on required showing some variable data, like signal strength, signal to noise ratio etc. As usual, I dived into Code Project, confident that I'll find a solution. I did find some, as expected, but unfortunately, none of them fit my requirements. First of all, I needed to show variables of different type, i.e. the control needed to have multiple bands. Secondly, the code needed to be windows CE compliant.

After some review, I choose Mehdi Mousavi's CHistogramCtrl, which was good enough to be portable to windows CE. All I did was add some modifications to include multiple bands support and that's it.

Using the code

Using  the code is pretty simple. All you do is add bands to the control using new instances of the COscilloscopeBand object. For example in the dialog's OnInitDialog method.

// m_Oscilloscope is the instance of COscilloscopeCtrl

m_Oscilloscope.m_Bands.Add(new COscilloscopeBand(_T("Band1"), 
    RGB(0x99, 0xFF, 0x66), 1, 1, 100));
m_Oscilloscope.m_Bands.Add(new COscilloscopeBand(_T("Band2"), 
    RGB(0, 0, 255), 1, 1, 200));

// Create the scope ctrl itself..., we'll place it over an 

//already existing static ctrl in the dialog

CRect rect;
GetDlgItem(IDC_STATIC_OSCILLOSCOPE)->GetWindowRect(rect);
ScreenToClient(rect);
m_Oscilloscope.Create(WS_VISIBLE | WS_CHILD, rect, this, 
    IDC_OSCILLOSCOPE);

You can set the position of a band by calling its SetPos method. You must also call DrawBands each time you want to update the display. COscilloscopeCtrl also contains some other helpful methods to modify the individual bands Pen width, color etc. Check out the source code.

Todo

Draw some sort of a legend to describe a band. I included a band name for a band's constructor for that purpose, but never got around doing it. Some help! :)

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here