Click here to Skip to main content
15,885,028 members
Articles / Desktop Programming / MFC

AIM-Style Scrolling Banner Control

Rate me:
Please Sign up or sign in to vote.
4.14/5 (4 votes)
30 Jun 20013 min read 108.4K   2.5K   29  
A scrolling banner control containing strings with individual styles and colors.
#ifndef BANNERSTATIC_H_
#define BANNERSTATIC_H_

//-------------------------------------------
// instead of using normal timers, we're 
// going to use multimedia timers
//
#pragma comment(lib, "winmm.lib")

#include "StdAfx.h"
#include "MultiColorStatic.h"
#include "Mmsystem.h"
#include "vector"
using std::vector;

typedef void (WINAPI* PFNBANNERITEMCLICK)(HWND, int, HWND);

class CBannerStatic : public CMultiColorStatic
{
public:     // construction
   CBannerStatic();
   virtual ~CBannerStatic();
   
private:
   CBannerStatic(const CBannerStatic& cSource);
   CBannerStatic& operator=(const CBannerStatic& cRight);

public:
   void SetScrollSpeed(const int& nSpeed);
   int GetScrollSpeed(void) const;
   void SetWrapText(const BOOL& fWrapText);
   BOOL GetWrapText(void) const;

   void SetItemCursor(const UINT& unItemCursor);
   void SetItemClickProc(PFNBANNERITEMCLICK pfnItemClick);

protected:
   void ScrollBanner(void);
   static void CALLBACK TimerProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2);
   
   void SetScrollSize(const int& nScrollSize);
   int  GetScrollSize(void) const;
   void SetScrollDelay(const DWORD& dwScrollDelay);
   DWORD GetScrollDelay(void) const;
   void CalculateScrollParameters(void);
   int FindStringFromPoint(CPoint point);
   LPARAM MakeParentPoint(CPoint point);

private:
   int   m_nBannerSpeed;   // -MAXSPEED <= m_nBannerSpeed <= MAXSPEED
   BOOL  m_fWrapText;      // should text wrap?
   UINT  m_tmScroll;       // timer identifier
   int   m_nTextOut;       // pixel to begin drawing text
   int   m_nTextLength;    // when text scrolls out of client rect, start over from the right
   int   m_nScrollSize;    // amount of pixels to move when scrolling
   DWORD m_dwScrollDelay;  // delay, in ms, for scrolling -- indirectly set by SetScrollSpeed

   vector<int> m_vnStrings;// beginning x-coordinates for each string
   HCURSOR m_hItemCursor;  // cursor for when you're over a string
   HCURSOR m_hStdCursor;   // standard cursor
   CPoint  m_ptCursor;     // so we know if we're over a string or not
   
   PFNBANNERITEMCLICK m_pfnItemClick;     // when an item is clicked, this function will be called
   
   static const int MAXSPEED;             // maxiumum speed the client is allowed
   static const int MAXSPEED_MODIFIER;    // used for determining scroll parameters
   static const int TIMERRESOLUTION;      // default for timeSetEvent function
   static const int STEPHEIGHT;           // when should we scroll by more than one pixel?

protected:
   virtual void PreSubclassWindow(void);

   afx_msg void OnTimer(UINT nIDEvent);
   afx_msg void OnPaint(void);
   afx_msg void OnSize(UINT nType, int cx, int cy);
   afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
   afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
   afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
   afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
   afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
   afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
   afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
   afx_msg void OnMouseMove(UINT nFlags, CPoint point);
   afx_msg void OnDestroy();

   DECLARE_MESSAGE_MAP()
};

#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions