Click here to Skip to main content
Click here to Skip to main content

Oscilloscope/StripChart Control

, 17 Jan 2000
Rate this:
Please Sign up or sign in to vote.
A control that graphically displays numerical information

Sample Image - oscope.gif


Despite the rather vast array of tools that are provided with Visual C++ one area that seems to be somewhat ignored is that which is concerned with graphical data analysis. There seem to be millions of ways of showing, sorting and relating text and numbers but no good ways of graphically displaying them. (In my world, one decent plot is worth a thousand CRichEditCtrl's.) Thus I'm always looking for a better way of graphically presenting information in an easily interpreted manner.

Historically, I've shown "live" gauge readings through the constant updating of a numerical value in a read-only edit control. However, apart from making the user seasick, this approach does not easily reveal subtle patterns or trends. This level of interpretation requires an "oscilloscope" or "strip chart" style display of historical data.

This OscopeCtrl is based on the bitmap shifting concept used in Ken C. Len's Histogram Control. It provides significant enhancements through the display of scaling information and plotting of double precision values. The user implementation is described below.

  1. In the control's owner (for example dialog) insert a dummy picture control.
  2. Size the picture border to be the desired size of the COScopeCtrl. Name the control something that sounds technical, like "IDC_OSCOPE".

  3. Insert the control in the owner class.
  4. Add a member variable of type COScopeCtrl.
    class CTestOScopeDlg : public CDialog
      // Construction
      COScopeCtrl m_OScopeCtrl;

  5. Create the control.
  6. Setup the control, placing it in the picture rectangle from step #1.
    BOOL CTestOScopeDlg::OnInitDialog()
      // determine the rectangle for the control
      CRect rect;
      GetDlgItem(IDC_OSCOPE)->GetWindowRect(rect) ;
      ScreenToClient(rect) ;
      // create the control
      m_OScopeCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this) ; 

  7. Personalize the Control
  8. Set the vertical range, background color, grid color and plot color.
    BOOL CTestOScopeDlg::OnInitDialog()
      // determine the rectangle for the control
      CRect rect;
      GetDlgItem(IDC_OSCOPE)->GetWindowRect(rect) ;
      ScreenToClient(rect) ;
      // create the control
      m_OScopeCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this) ; 
      // customize the control
      m_OScopeCtrl.SetRange(-10.0, 10.0, 1) ;
      m_OScopeCtrl.SetYUnits("Volts") ;
      m_OScopeCtrl.SetXUnits("Samples (Windows Timer: 100 msec)") ;
      m_OScopeCtrl.SetBackgroundColor(RGB(0, 0, 64)) ;
      m_OScopeCtrl.SetGridColor(RGB(192, 192, 255)) ;
      m_OScopeCtrl.SetPlotColor(RGB(255, 255, 255)) ;

  9. Use the control.
  10. Call the COScopeCtrl::SetPosition function with the the data value to be appended to the plot. Subsequent calls to SetPosition will continue to shift the plot to the left.

  11. Other Considerations
    1. Color Selection
    2. The OScopeCtrl optimizes the drawing of the plot for the sake of speed and smoothness of animation. In this approach, memory based device contexts and associated bitmaps are constructed for 1.) the underlying grid and 2.) the plot line segments. These two bitmaps are combined in another memory based display context to avoid flicker. During the painting of the control, the grid is BitBlt'd (as a SRCCOPY), the plot is then added by BitBlt'ing it as a "pattern" via SRCPAINT. The result is then BitBlt'd to the display (as SRCCOPY). (See the COScopeCtrl::OnPaint function for details.)

      This approach is quite clean and fast for light colored plots and light colored grids which are to be displayed on dark colored backgrounds. For some light colored backgrounds, the plot and/or grid may not be displayed do to the OR'ing nature of the SRCPAINT-style BitBlt.

    3. Font Selection
    4. The COScopeCtrl draws the axis information text in a font which is 14 pixels high. The attributes for both the horizontal and vertical fonts can be modified in the COScopeCtrl::InvalidateCtrl() function.

    5. Further Customization
    6. The COScopeCtrl constructor sets a most of the default behavior and is thoroughly documented. These values can be modified to achieve different styles of displays.

      Try this one for fun.

      To give the feel of an old green oscilloscope display, try these settings:
        m_OScopeCtrl.SetRange(-10, 10, 1) ;
        m_OScopeCtrl.SetYUnits("Volts") ;
        m_OScopeCtrl.SetXUnits("Samples (Windows Timer: 100 msec)") ;
        m_OScopeCtrl.SetBackgroundColor(RGB(0, 64, 0)) ;
        m_OScopeCtrl.SetGridColor(RGB(192, 255, 192)) ;
        m_OScopeCtrl.SetPlotColor(RGB(255, 255, 255)) ;


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

Mark C. Malburg
Software Developer (Senior) Digital Metrology Solutions, Inc.
United States United States
No Biography provided

Comments and Discussions

GeneralRe: Added Y-Axis Autoranging Pinmemberaz0te19-Apr-04 6:07 
GeneralRe: Added Y-Axis Autoranging PinmemberGilrock19-Apr-04 6:44 
GeneralRe: Added Y-Axis Autoranging Pinmemberaz0te19-Apr-04 10:20 
GeneralRe: Added Y-Axis Autoranging Pinmemberkezhu30-Mar-08 22:41 
GeneralRe: Added Y-Axis Autoranging Pinmemberchen_ylu21-Feb-08 22:43 
GeneralRe: Added Y-Axis Autoranging PinmemberIkey_Boy18-Jan-07 2:50 
QuestionHow to port This MFC code to WTL code ? PinmemberAtomic Jo5-May-03 20:07 
GeneralRefreshing problems PinmemberTaylorLee15-Jul-02 15:28 
This is not a problem with your code, but is a problem that I face which affects the display of your code.
My program controls a multimeter type device and retrieves data from said device. I use your code to display the data in a nice form. But the problem is that when another window (let's call this window B) obscures the graphing window, and then window B is then minimized to un-obscure the graphing window, the graphing window does not repaint itself. More specifically, the whole graphing window is the shade of gray which is the background of the graphing window.
The pseudocode of part of my program is like this:
Is there a function I can call after the Read_multimeter() function which will repaint the graphing window so when some other window obscures it, the graphing window will repaint itself? I've used Invalidate() and InvalidateRect() without success. BTW, my program's main window is a dialog box, so the graph is in one corner of the main window. I am new to win32 programming, so please be kind! thanks!
GeneralSome colors cannot be shown Pinmemberannonymos5-Feb-02 20:11 
GeneralRe: Some colors cannot be shown PinmemberMark C. Malburg6-Feb-02 2:56 
GeneralRe: Some colors cannot be shown Pinmemberannonymos6-Feb-02 12:10 
GeneralRe: Some colors cannot be shown Pinmemberxradish14-Jul-03 20:16 
GeneralRe: Some colors cannot be shown Pinmemberkezhu29-Sep-03 20:12 
Questionmemory leak? PinmemberAnonymous13-May-01 5:37 
AnswerRe: memory leak? Pinmemberanonymous18-Feb-02 20:22 
GeneralRe: memory leak? PinsussAnonymous1-Oct-03 19:00 
GeneralRe: memory leak? Pinmemberbaldo13-Jan-04 0:59 
AnswerRe: memory leak? Pinmemberkezhu30-Mar-08 22:49 
QuestionWhat about a new feautre? PinmemberPV5-May-01 13:32 
GeneralResize doesn't work. PinmemberMasoud15-Dec-00 17:18 
GeneralRe: Resize doesn't work. Pinmemberyeol23812-Dec-05 14:53 
QuestionHow can you use this in a view? PinsussMartin MacRobert10-Feb-00 0:05 
AnswerRe: How can you use this in a view? PinsussDon21-Feb-00 10:30 
GeneralRe: How can you use this in a view? Pinmembermub21-Jan-03 14:21 
QuestionWhat about print support? PinsussDon9-Feb-00 17:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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.150129.1 | Last Updated 18 Jan 2000
Article Copyright 2000 by Mark C. Malburg
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid