Shop for Software

CodeGuru Sites
Visual C++ / MFC / C++ .NET (C# and more) Visual Basic Gamelan (Java) JARs (Java Applets)
Developer.com

submission guidelines

Interact
Discussion Boards Newsletters (subscribe) Guestbook Recommend Us!

Of Interest
Books on .NET Book Reviews Newsletters (archived) About Us

Article Sections
C++ algorithms & formulas c++ & mfc date & time string
COM-based Technologies atl & wtl com & activex com+ shell programming
Controls button control combobox edit control imagelist control
listbox control
listview control
menu
other controls
property sheet
rich edit control
static control
status bar
toolbar
treeview control
Data database miscellaneous
Frameworks ui & printing frameworks
Graphics & Multimedia bitmaps & palettes directx gdi multimedia
opengl
Internet & Networking ie programming internet protocols isapi network protocols
Miscellaneous miscellaneous samples
Visual Studio debugging add-ins & macros editor tips
Windows Programming ce clipboard dll file & folder
help systems
printing
win32
system
Windows & Dialogs console dialog docking window doc/view
splitter

internet.commerce
Be a Commerce Partner Free Barter Account Register Domains Web Edit Tools Shopping Cart Software
CreditCard Processing
Tech Magazines - FREE
Submit Your Site
Send a Press Release
Software Store
Promote Your Website

### Oscilloscope/StripChart Control

This article was contributed by Mark C. Malburg.

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.

Size the picture border to be the desired size of the OScopeCtrl. Name the control something that sounds technical, like "IDC_OSCOPE".

2. Insert the control in the owner class.

Add a member variable of type COScopeCtrl.

    class CTestOScopeDlg : public CDialog
    {
      // Construction
      ...
    protected:
      COScopeCtrl m_OScopeCtrl;
      ...
    }

2. Create the control.

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) ;
      ...
    }

3. Personalize the Control

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)) ;
      ...
    }

4. Use the control.

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.

      ...
      m_OScopeCtrl.AppendPoint(nRandom);
      ...

Other Considerations

A. Color Selection

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.

B. Font Selection

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.

C. Further Customization

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)) ;

Download demo project - 25 KB

Download source - 6 KB

Date Posted: January 10, 1999

### Comments:

- In need of ActiveX edition - zabbas (2002/09/04)
- How to use in Embedded Visual C++. (Follow up) - Zaheer Abbas (2002/08/30)
- Problems with running under Embedded Visual C++ ? - Marco Braun (2002/07/16)
- Hide OScopeCtrl - Samuel Gerber (2002/03/25)
- Ocsiloscope - nsa (2002/03/14)
- Is similar code available for ActiveX control in VB - atul (2001/10/10)
- REsizing problem + Dynamic Y-Axis Scaling - hebeman (2001/04/03)
- Left to Right - Stefan (2001/03/18)
- New: (1) display multiple trends at once, (2) specify x/y axis min/max labels as texts, (3) add a gap in the trend, (4) fixed number of points in whole width of trend - Gregory Hayduk (2000/12/01)
- X-axis-scaling for Oscope available - Mark Henning (2000/11/02)
- Multiple series on the one graph - Anthony (2000/05/16)
- How to print it in a document-view program - Joshua Liu (2000/05/15)
- How Program including COScopeCtrl to Use the MFC's Print and PrintView - denver Yu (2000/03/28)
- Scalable x axis and Grid??? please!!! - John Holmes (2000/02/09)
- Fixes for Oscilloscope mode suggestion of Peter O'Conner - David Leikis (1999/10/14)
- Use CDC::ScrollDC for bitmap shifting - Martin MacRobert (1999/09/30)
- Anyone have this working from a DLL??? - Alan Rencher (1999/09/15)
- Oscilloscope/StripChart Control and Windows 98 bug - Brian (1999/08/25)
- How to draw a graph using VC++ - Dinesh (1999/08/24)
- Real time data.. - Vishalakshi Kakhandki (1999/08/10)
- An ActiveX version of OScope - Duane Mattern (1999/06/30)
- Small Problems With OScope - Doug Joseph (1999/06/06)
- How to enhance the Client Area by using HSCroll adnd VScroll? - John XU (1999/05/25)
- Allow any background color...(2nd try.) - Jйrфme Isabelle (1999/05/19)
- Vertical grid for precision - More than one graphic - Jose Luis Flores (1999/05/18)
- allow using of any color background, grid or lines. - Jйrфme Isabelle (1999/05/13)
- OScope - rupa (1999/03/16)
- Catching mouseclicks in a bitmap - Maria Larsson & Inger Andersson (1999/02/15)
- Resizing Fix - John Gann (1999/01/14)
- Modification to allow Scope-like left to right drawing - Peter O'Connor (1999/01/14)
- Oscilloscopes draw Left to Right ! - Hans Wedemeyer (1999/01/12)
- 1 small documentation fix - Brad Bruce (1999/01/12)
- Beautiful - Peter O'Connor (1999/01/12)
- nice and smooth - Mark (1999/01/10)

Add Comment

EarthWeb is a service of Jupitermedia Corp.
Copyright 2002 Jupitermedia Corp. All Rights Reserved.
Feedback, Advertising Info, Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.