Click here to Skip to main content
13,832,996 members
Click here to Skip to main content
Add your own
alternative version


37 bookmarked
Posted 6 Aug 2002

Trend Display

, 6 Aug 2002
Rate this:
Please Sign up or sign in to vote.
A simple document/view application to display an online curve of time dependent values

What is Trend Display?

Trend Display is an area to show time dependent values in form of curves for different purposes. For example if you want to monitor some hardware quantities that are time dependent such as voltage, temperature and something like these the Trend Display is a good area to display the changes of those signals value in different times.

How does it work?

For this purpose I've created a CFormView based class called CTrendView with related document and frame classes ( CTrendDoc and CTrendFrame ). By using these classes in a MDI project you can have a multiple documents Trend Display. It's very easy to use. Just you should register the Trend's document templates in InitInstance() method of application class.

// declaration in header file 
CMultiDocTemplate* pDocTemplate;  
m_pTrendTemplate = new CMultiDocTemplate(IDR_TrendTestTYPE, 
        // custom MDI child frame 

Also because of using a CFormView class you need to add a dialog resource (IDD_FORMVIEW) to your project. Now you can open Trend Display in any way you desire for example through a menu or toolbar.

void CTrendTestApp::OnTrendOpen() 

A ruler that moves horizontally, signifies the current time. This ruler moves pixel by pixel by a timer, which is used in CTrendView class. There is no need to any special code for invalidating the OnDraw function when Trend window moves, resize or disappears behind the other windows, because there is a buffer to hold the values for each signal.

void CTrendView::DrawTrend() 
    m_pDC = GetDC(); 
    for(BYTE j=0 ; j < m_pDoc->m_noOfPoint ; j++) 
        CPen pen(PS_SOLID,1,m_pDoc->m_pPoint[j].Color); 
        m_OldPen = m_pDC->SelectObject(&pen); 
        for(int i=1 ; 
            i < m_pDoc->m_pPoint[j].BufferedValue.GetSize(); 
            m_portion = 
                (m_pDoc->m_pPoint[j].BufferedValue[i-1] -
                / m_pDoc->m_pPoint[j].Range; 

                int(m_trendRect.bottom - 

            m_portion = (m_pDoc->m_pPoint[j].BufferedValue[i] - 
                / m_pDoc->m_pPoint[j].Range; 

                int(m_trendRect.bottom -
    InvalidateRect(CRect(m_trendRect.left + 


I didn't use any options for this project but it could has many options. For example the back ground color and signals color can be changeable and grids, scales and scan time as well. May be in my upcoming version I add these options to my code. But it's better that you put these possibilities as you desire. The attached demo project is created and compiled with MFC7, so to compile it, you need VS.NET but it's very easy to add source code to your MFC6 based project. Please feel free to send your comments, questions and suggestions about this Trend Display. Thank you in advance.


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

Majid Shahabfar
Software Developer (Senior)
Iran (Islamic Republic of) Iran (Islamic Republic of)
Majid is a well-experienced .NET developer who directs his own community which is a Microsoft software development technology community for Persian native developers.
He is involved in many kind of software projects and also doing some tasks on High Performance Computing including massive parallel computing and GPU programming.
He is working as a software designer and developer and also as a consultant for some IT related companies.

You may also be interested in...

Comments and Discussions

Generaldoesn't work under MSVC6 Pin
general.failure26-Jun-03 6:00
membergeneral.failure26-Jun-03 6:00 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.190114.1 | Last Updated 7 Aug 2002
Article Copyright 2002 by Majid Shahabfar
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid