Click here to Skip to main content
15,891,409 members
Articles / Desktop Programming / MFC
Article

COscilloscopeCtrl

Rate me:
Please Sign up or sign in to vote.
4.48/5 (17 votes)
14 Mar 2003BSD1 min read 62.1K   4.6K   40   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, along with any associated source code and files, is licensed under The BSD License


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralOnSize Pin
Anonymous7-Oct-03 16:14
Anonymous7-Oct-03 16:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.