Click here to Skip to main content
13,046,464 members (75,228 online)
Click here to Skip to main content
Add your own
alternative version


50 bookmarked
Posted 30 Aug 2000

A Ticker control

, 3 Sep 2000
Rate this:
Please Sign up or sign in to vote.
A class that provides a news/stock ticker for your MFC applications
<!-- Download Links -->
  • Download source files - 7 Kb
  • Download demo project - 34 Kb
  • <!-- Article image -->

    Sample Image - AppPic.jpg

    <!-- Main HTML starts here -->


    An MFC class CTicker that could be used to provide a news/stock ticker for your MFC applications.

    Imagine there is a requirement in your project where you need to display scrolling information in an application that delivers timely information on stocks, news, sports scores, and weather.

    A 'Mouse Over' event stops the ticker and highlights the border, and clicking on it would open a predefined URL in your favourite browser with more detailed information in the html files. There are similar applications available on the net, for example EntryPoint.

    The ticker should continuously display changing data and download the URL specified at regular intervals and display that data. The data can be in text format.

    I always wished there was a readymade class that enabled my application to display a scrolling ticker. I had to resort to Third party ActiveX controls which added considerable size to my applications and versioning headaches. So I wrote one myself and in the spirit of MFC I call it CTicker.

    I have done GDI with MFC's wrapper classes and used the CAsyncMonikerFile class to achieve HTTP.

    The sample code is a Dialog based app called TickerTest. One could try out other combinations of MFC applications.


    To add the ticker to TickerTest you need to do the following:

    1. Drop a Static/label control on the dialog resource IDD_TICKERTEST_DIALOG. Give it an appropriate resource id IDC_STATIC1 (say). Do not select the Notify property for the static control.

    2. Add a member variable for the particular static control. Give it the name m_sTicker & select a category of type Control. This would make the variable type CStatic automatically.

    3. Open the class TickerTestDlg.h and add the line #include "Ticker.h" on top to include the declarations of the CTicker class. Replace the class CStatic with CTicker.

    4. Add a member variable m_TickerRect to the class CTickerTestDlg. This variable holds the window coordinates for the ticker.

    5. Override the OnInitDialog function for the class CTickerTestDlg

    6. Call the function m_sTicker.GetWindowRect (&m_TickerRect) to set the ticker's window coordinates.

    7. Call the one stop function ShowRates or the ShowRatesWithBkgBmp passing it the following relevant parameters:

      • Name of the file containing the quotes,
      • Text color on ticker,
      • Color of text of rates(RATES mode),
      • FontName,
      • FontHeight,
      • TickerSpeed,
      • TickerMode (Regular mode which displays only information OR the Rates mode which displays information in the format CompanyName followed by CompanyRate slightly below in height and so on...),
      • Bitmap Resource ID


                          "Comic Sans MS",


    8. For the MouseOver override WM_MOUSEMOVE message, and add a handler to the class CTickerTestDlg and add the following code
      void CTickerTestDlg::OnMouseMove(UINT nFlags, CPoint point) <br>
      	CDialog::OnMouseMove(nFlags, point);
      	m_sTicker.GetWindowRect (&m_TickerRect);
      	ClientToScreen (&point);
      	TRACK_TICKER_MOUSEMOVE(m_sTicker, m_TickerRect)

      Take a look at the TRACK_TICKER_MOUSEMOVE macro. This Macro takes the CTicker based object name the CRect object name representing the window coordinates. This macro changes two properties of the CTicker class based on which it draws a Rectangular border around the ticker on mouseover.

    9. For the Click-go-to-URL feature handle the WM_LBUTTONUP message by adding a handler to the class CTickerTestDlg and add the following code
      void CTickerTestDlg::OnLButtonUp(UINT nFlags, CPoint point)
      	CDialog::OnLButtonUp(nFlags, point);
      	if (m_TickerRect.PtInRect (point))
      		AfxMessageBox("Will open in the browser now");
      		ShellExecute(0 ,"open", "", NULL, NULL, SW_MAXIMIZE);
    10. For the Fetch-via-HTTP feature do the following: (This feature uses Asynchronous Monikers) Add a new Class through the class wizard(CTRL-W)

      Override the OnDataAvailable and OnProgress (If progress indication is required) messages and add the following code to OnDataAvailable

      void CMyAsyncMon::OnDataAvailable(DWORD dwSize, DWORD bscfFlag)
          if ((bscfFlag & BSCF_LASTDATANOTIFICATION) != 0)
      		char* m_buffer;
      		m_buffer = (char*)malloc(dwSize*sizeof(char) + 1);
      		try {
      			UINT nBytesRead = Read(m_buffer,dwSize);
      			m_buffer[nBytesRead] = '\0';
      			CFile f1;
      			if( f1.Open( "Ticker2.txt", CFile::modeCreate | CFile::modeWrite ) ) 
      				f1.Write(m_buffer, strlen(m_buffer));
      				//Retrive a pointer to the main window 
      				//Access the public(eeeks) variable m_sTicker2
      				//and set the text to be displayed in the ticker
      				CTickerTestDlg* pDlgMain = (CTickerTestDlg*)AfxGetMainWnd();
      				pDlgMain->m_sTicker2.SetTickerText (m_buffer);
      		catch(CFileException* pe)
      			pe->Delete ();
      	CAsyncMonikerFile::OnDataAvailable(dwSize, bscfFlag);

      This is how a typical TextFile containing CompanyName/Quotes with delimiters are:

    Authors Note

    I made the class CTicker for open use. If it works with you please give credit where I deserve. Please send me some feedback .

    There are more articles coming on server side MTS Components which generates stock exchange feed at runtime from various quote providers on the net. These server side components along with the client side ticker(as a custom app or an activeX control) help in creation of a great Online Stock Portfolio WITHOUT subscribing to expensive stock feed from quote providers.

    Special thanks to Fabian Toader for providing The CJumpyDraw class
    I have borrowed the DrawLinearWash function from his class to provide the gradient look.


    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

    Ranjeet Chakraborty
    Web Developer
    United States United States
    I am originally from Mumbai, India, Currently living in Los Angeles doing Software Development. If there is something I miss here in LA, its the crazy Mumbai monsoon and delicious "wadapavs".
    Apart from spending time writing software, I spend most of my time with XBox riding the Warthog and killing covenants in Halo.

    You may also be interested in...


    Comments and Discussions

    Generalhelp me with code Pin
    no_body6916-Jun-03 19:51
    memberno_body6916-Jun-03 19:51 

    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 | Terms of Use | Mobile
    Web02 | 2.8.170713.1 | Last Updated 4 Sep 2000
    Article Copyright 2000 by Ranjeet Chakraborty
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid