Click here to Skip to main content
11,925,073 members (56,704 online)
Click here to Skip to main content
Add your own
alternative version


82 bookmarked

Oscilloscope control

, 23 Jun 2004
Rate this:
Please Sign up or sign in to vote.
WTL Oscilloscope control.

Sample Image


This is a simple implementation of Oscilloscope control. This control shows last N points of user data. It has up to 8 channels (number of channels are defined by OSC_MAX_CHANNELS parameter in header file). Each channel can show only one curve (in this version). Oscilloscope includes zoom in implementation by X (Horizontal), by Y (Vertical), and by both axes simultaneously (Rectangle). Zoom out is also available by pressing right mouse button in channel area (hold CTRL key to full zoom out).

Using the code

To use this control in your application:

  • Design the dialog and add the Static control.
  • Add the Oscilloscope.h header file to your project.
  • Assign a OscilloscopeCtrl to your static control.
  • In OnInitDialog(), subclass OscilloscopeCtrl control to ID using the SubclassWindow method.

Don't forget to turn on any channels you need.

#include <span class="code-string">"Oscilloscope.h"


class CMainDlg : public CDialogImpl<CMainDlg>
       MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)          
    LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
        LPARAM /*lParam*/, BOOL& /*bHandled*/);
    OscilloscopeCtrl m_oscill;     


LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, 
      LPARAM /*lParam*/, BOOL& /*bHandled*/) 
     m_oscill.SubclassWindow( ::GetDlgItem( IDC_AREA ) );     

After creating Oscilloscope control, you can set special colors for curves and background (for each channel), point styles (how to draw the data points of curves), turn on/off grid, padding, and set padding coefficient. Padding is auto calculating value and used to offset curve by Y axis. By increasing padding coefficient (k>1), it is possible to decrease the gap between curve and channel top boundary box. If k<1, the gap will be increased (then k != 0). You can change oscilloscope layout by turning on/off X and Y axes and changing their positions (up or bottom for X axis; left or right for Y axis). Important: X axis is only one for all channels and Y axis is unique for every channel.

m_oscil.UseGrid(true); // trun on grid
m_oscil.UsePadding(true); // use padding
m_oscil.PaddingCoef(2.0); // set padding coefficient
m_oscil.PointStyle(UTriangle); // set point style to UTriangle
m_oscil.GetChannel(0)->SetLnColor( RGB(0,255,0) ); // green curve
m_oscil.GetChannel(0)->SetBgColor( RGB(0,0,0) ); // white background
m_oscil.BottomXAxis(true); // adds bottom X axis
m_oscil.LeftYAxis(true); // adds left Y axis

Then you need to supply data for oscilloscope (pointers to double arrays). It's important that double arrays you pass to oscilloscope have to be global. To increase drawing speed, oscilloscope doesn't copy data to its buffers (!!!). The double arrays contains only Y values, oscilloscope calculates X values automatically by using user time.

// number of arrays have to be equal to OSC_MAX_CHANNELS !!!
// but if you don't need data for example
// for channel 1 the m_values[1] can be NULL
double*  m_values[OSC_MAX_CHANNELS];
size_t   m_cnt;
size_t   m_time;
m_oscil.SetPoints(m_time, m_values, m_cnt);


  • Removed using namespace std from header file Smile | :)
  • Added double buffering to avoid flickering on draw (thanks to Michal Mecinski)

      Demo program

      The small demo program shows how to use the oscilloscope control. Add buttons to control its layout, to change zoom mode, points styles, last points, and etc. You can change source code for any future usage.

    • 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


      About the Author

      Web Developer
      Russian Federation Russian Federation
      No Biography provided

      You may also be interested in...

      Comments and Discussions

      QuestionHow to change moving grids to fixed grids? Pin
      zanexino4-Mar-15 22:31
      memberzanexino4-Mar-15 22:31 
      Questionis it good and fast for 200 values per second ? Pin
      moibrahim19-Sep-14 10:45
      membermoibrahim19-Sep-14 10:45 
      QuestionThank you Pin
      futurejo27-Sep-11 21:09
      memberfuturejo27-Sep-11 21:09 
      GeneralSetPoints Pin
      justinlacroix17-Nov-06 7:01
      memberjustinlacroix17-Nov-06 7:01 
      GeneralVery slow :( Pin
      HyperThreading24-Oct-06 10:39
      memberHyperThreading24-Oct-06 10:39 
      GeneralHelp to create MFC program using Oscilloscope Pin
      Muralish16-Sep-06 21:52
      memberMuralish16-Sep-06 21:52 
      GeneralPossible Bug Pin
      PiotrGutkowski28-Mar-06 8:26
      memberPiotrGutkowski28-Mar-06 8:26 
      QuestionOscilloscope? Really? Pin
      Michael__Ber21-Jan-06 21:25
      memberMichael__Ber21-Jan-06 21:25 
      AnswerRe: Oscilloscope? Really? Pin
      kezhu25-Mar-08 21:59
      memberkezhu25-Mar-08 21:59 
      This one (oscilloscope-lib) doesn't give you souce codes so you don't have the flexibility by using your own codes.

      Also I have a question, how to set pre-trigger and post-trigger? Any suggestions/advice?


      GeneralThis one (oscilloscope-lib) doesn't give ... Pin
      Michael__Ber26-Mar-08 8:02
      memberMichael__Ber26-Mar-08 8:02 
      Generalmutliple siginals Pin
      rbuchana6-Jan-06 12:09
      memberrbuchana6-Jan-06 12:09 
      GeneralRe: mutliple siginals Pin
      rbuchana20-Feb-06 7:34
      memberrbuchana20-Feb-06 7:34 
      Generaldisplay sound Pin
      TassadaqHussain15-Aug-05 13:30
      memberTassadaqHussain15-Aug-05 13:30 
      Generalto MFC Pin
      EMTA4119-May-05 3:00
      memberEMTA4119-May-05 3:00 
      GeneralRe: to MFC Pin
      Alexander Yadykin8-Jun-05 4:43
      memberAlexander Yadykin8-Jun-05 4:43 
      GeneralRe: to MFC Pin
      Schwenner Simon13-Jun-05 6:28
      memberSchwenner Simon13-Jun-05 6:28 
      GeneralRe: to MFC Pin
      Alexander Yadykin13-Jun-05 21:04
      memberAlexander Yadykin13-Jun-05 21:04 
      GeneralRe: to MFC Pin
      Schwenner Simon14-Jun-05 2:28
      memberSchwenner Simon14-Jun-05 2:28 
      GeneralPlease HELP with MISSING Files Pin
      vishnya5-Apr-05 13:11
      membervishnya5-Apr-05 13:11 
      GeneralRe: Please HELP with MISSING Files Pin
      gyar6-Apr-05 12:16
      membergyar6-Apr-05 12:16 
      GeneralRe: Please HELP with MISSING Files Pin
      Anonymous6-Apr-05 13:12
      sussAnonymous6-Apr-05 13:12 
      GeneralRe: Please HELP with MISSING Files Pin
      vishnya6-Apr-05 13:41
      membervishnya6-Apr-05 13:41 
      Questioncould you give me missed files? Pin
      windshade11-Aug-04 12:28
      memberwindshade11-Aug-04 12:28 
      AnswerRe: could you give me missed files? Pin
      Anonymous6-Apr-05 13:24
      sussAnonymous6-Apr-05 13:24 
      GeneralSpeed Pin
      manu7772-Aug-04 23:18
      membermanu7772-Aug-04 23:18 
      GeneralOsc screen Pin
      gyar1-Jul-04 5:39
      membergyar1-Jul-04 5:39 
      Questionmissing files ? Pin
      MaxHacker24-Jun-04 8:55
      memberMaxHacker24-Jun-04 8:55 
      AnswerRe: missing files ? Pin
      autodebug15-Sep-04 15:57
      memberautodebug15-Sep-04 15:57 
      GeneralImpressive Pin
      Michal Mecinski22-Jun-04 2:38
      memberMichal Mecinski22-Jun-04 2:38 
      GeneralRe: Impressive Pin
      Isaac Anietye Inyang22-Jun-04 6:46
      memberIsaac Anietye Inyang22-Jun-04 6:46 
      GeneralRe: Impressive Pin
      Greg Peter-Joyal22-Jun-04 7:56
      memberGreg Peter-Joyal22-Jun-04 7:56 
      GeneralRe: Impressive Pin
      Isaac Anietye Inyang22-Jun-04 8:59
      memberIsaac Anietye Inyang22-Jun-04 8:59 
      GeneralRe: Impressive Pin
      Leslie Sanford25-Jun-04 19:13
      memberLeslie Sanford25-Jun-04 19:13 
      GeneralRe: Impressive Pin
      Voland723-Jun-04 0:22
      memberVoland723-Jun-04 0:22 
      GeneralRe: Impressive Pin
      Igor Vigdorchik23-Jun-04 8:30
      memberIgor Vigdorchik23-Jun-04 8:30 

      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.

      | Advertise | Privacy | Terms of Use | Mobile
      Web01 | 2.8.151125.3 | Last Updated 24 Jun 2004
      Article Copyright 2004 by Voland7
      Everything else Copyright © CodeProject, 1999-2015
      Layout: fixed | fluid