ScrollerCtrl.h
上传用户:hnzyys
上传日期:2015-09-10
资源大小:423k
文件大小:4k
源码类别:

通讯编程

开发平台:

Visual C++

  1. // CScrollerCtrl : class definition // Copyright 2002, Joshua Heyer //  You are free to use this code for whatever you want, provided you // give credit where credit is due: if you use this code without substantial // modification, please presearve this comment block. //  I'm providing this code in the hope that it is useful to someone, as i have // gotten much use out of other peoples code over the years. //  If you see value in it, make some improvements, etc., i would appreciate it  // if you sent me some feedback. //  Have fun! // #ifndef _SCROLLER_CTRL_H_INCLUDED_
  2. #define _SCROLLER_CTRL_H_INCLUDED_
  3. class CScrollerCtrl : public CWnd
  4. {
  5. public:
  6. CScrollerCtrl();
  7.    // public API
  8.    // create the window; remove WS_VSCROLL to avoid showing scrollbar, remove WS_TABSTOP to disable keyboard scrolling.
  9. BOOL Create(const RECT& rect, CWnd* pParentWnd, UINT uStyle = WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|WS_GROUP, UINT nID = 0);
  10.    // activate/deactivate wrapping mode:
  11.    void SetWrapping(BOOL bWrap);
  12.    // Sets the color used for the background (if no pattern is set) or margins (if pattern is set and not tiled)
  13.    void SetBgColor(COLORREF clrBg);
  14.    // Sets the color used for text
  15.    void SetFgColor(COLORREF clrBg);
  16.    // Sets the font; size is in points, see LOGFONT documentation for weight constants
  17.    void SetFont(const CString& strName, int nSize, int nWeight);
  18.    // Sets the text to be displayed
  19.    void SetText(const CString& strText);
  20.    // Sets the bitmap to be displayed above the text
  21.    CBitmap* SetLogo(CBitmap* pbmpLogo);
  22.    // Sets the background pattern
  23.    CBitmap* SetPattern(CBitmap* pbmpPattern, BOOL bTile);
  24.    // Sets the time between frames (autoscrolling speed) (will revert to default if less than 0) (milliseconds)
  25.    void SetScrollDelay(int nScrollDelay);
  26.    // Sets the delay when autoscrolling pauses (will disable pausing if set less than scroll delay) (milliseconds)
  27.    void SetScrollPause(int nScrollPause);
  28.    // command messages:
  29.    // sent when text has scrolled completely off the window
  30.    static const int  SC_SCROLL_COMPLETE;
  31. protected:
  32.    // utility: override these in a derived class if you
  33.    // want to do something fancy.
  34.    virtual void RecalcLayout(CDC* pDC);
  35.    virtual void FillBackground(CDC* pDC);
  36. virtual int DrawLogo(CDC* pDC, int nOffset, BOOL bDraw = TRUE);
  37. virtual int DrawBodyText(CDC* pDC, int nOffset, BOOL bDraw = TRUE);
  38.    // message handlers
  39. afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  40. afx_msg UINT OnGetDlgCode();
  41. afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  42. afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  43. afx_msg void OnPaint();
  44. afx_msg void OnTimer(UINT nIDEvent);
  45.    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  46.    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  47. DECLARE_MESSAGE_MAP()
  48. private:
  49.    // defaults
  50.    static const int   nSCROLL_DELAY;   // time between each frame (milliseconds)
  51.    static const int   nSCROLL_PAUSE;   // time to pause before autoscrolling (milliseconds)
  52.    static const int   nMARGIN;         // (pixels)
  53.    static const int   nFONT_SIZE;      // (points)
  54.    static const int   nFONT_WEIGHT;
  55.    static const char* szFONT_NAME;
  56.    // instance data
  57.    enum { SCROLLING, PAUSED } m_eState;
  58. COLORREF m_crBackground;
  59. COLORREF m_crForeground;
  60.    CFont    m_font;
  61.    CString  m_strText;
  62.    CBitmap* m_pbmpPattern;
  63. CBitmap* m_pbmpLogo;
  64. CBitmap  m_bmpBackBuffer;
  65. CSize    m_sizeBuffer;
  66. int      m_nContentHeight;
  67. int      m_nScrollOffset;
  68.    BOOL     m_bTilePattern;
  69.    BOOL     m_bShowScroll;
  70.    BOOL     m_bWrap;
  71.    int      m_nScrollDelay;
  72.    int      m_nScrollPause;
  73.    UINT_PTR m_unTimerPause;
  74. };
  75. #endif _SCROLLER_CTRL_H_INCLUDED_