XScrollBar.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // XScrollBar.h Version 1.1
  2. //
  3. // Author: Hans Dietrich
  4. // hdietrich@gmail.com
  5. //
  6. // License:
  7. // This software is released into the public domain. You are free to use
  8. // it in any way you like, except that you may not sell this source code.
  9. //
  10. // This software is provided "as is" with no expressed or implied warranty.
  11. // I accept no liability for any damage or loss of business that this
  12. // software may cause.
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #ifndef XSCROLLBAR_H
  16. #define XSCROLLBAR_H
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CXScrollBar
  19. class CXScrollBar : public CStatic
  20. {
  21. // Construction
  22. public:
  23. CXScrollBar();
  24. virtual ~CXScrollBar();
  25. BOOL CreateFromStatic(DWORD dwStyle,
  26. CWnd* pParentWnd,
  27. UINT nIdStatic,
  28. UINT nId);
  29. // Attributes
  30. public:
  31. void EnableChannelColor(BOOL bEnable) { m_bChannelColor = bEnable; }
  32. void EnableThumbColor(BOOL bEnable) { m_bThumbColor = bEnable; }
  33. void EnableThumbGripper(BOOL bGripper) { m_bThumbGripper = bGripper; }
  34. int GetScrollPos() const { return m_nPos; }
  35. int SetScrollPos(int nPos, BOOL bRedraw = TRUE);
  36. void SetScrollRange(int nMinPos, int nMaxPos, BOOL bRedraw = TRUE);
  37. void SetThumbColor(COLORREF rgb) { m_ThumbColor = rgb; m_bThumbColor = TRUE; }
  38. void SetThumbHoverColor(COLORREF rgb) { m_ThumbHoverColor = rgb; }
  39. void MoveWindowEx(int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE)
  40. { MoveWindow(x, y, nWidth, nHeight); GetClientRect(&m_rectClient); }
  41. // Operations
  42. public:
  43. void ScrollLeft();
  44. void ScrollRight();
  45. void ScrollUp();
  46. void ScrollDown();
  47. // Overrides
  48. // ClassWizard generated virtual function overrides
  49. //{{AFX_VIRTUAL(CXScrollBar)
  50. //}}AFX_VIRTUAL
  51. // Implementation
  52. protected:
  53. CWnd * m_pParent; // control parent
  54. int m_nThumbLeft; // left margin of thumb
  55. int m_nThumbTop; // top margin of thumb
  56. int m_nBitmapHeight; // height of arrow and thumb bitmaps
  57. int m_nBitmapWidth; // width of arrow and thumb bitmaps
  58. int m_nPos; // current thumb position in scroll units
  59. int m_nMinPos; // minimum scrolling position
  60. int m_nMaxPos; // maximum scrolling position
  61. int m_nRange; // absolute value of max - min pos
  62. CRect m_rectThumb; // current rect for thumb
  63. CRect m_rectClient; // control client rect
  64. HCURSOR m_hCursor; // hand cursor
  65. COLORREF m_ThumbColor; // thumb color
  66. COLORREF m_ThumbHoverColor; // thumb color when mouse hovers
  67. BOOL m_bThumbColor; // TRUE = display thumb with color
  68. BOOL m_bChannelColor; // TRUE = display color in channel
  69. BOOL m_bThumbGripper; // TRUE = display thumb gripper
  70. BOOL m_bThumbHover; // TRUE = mouse is over thumb
  71. BOOL m_bMouseDownArrowRight; // TRUE = mouse over right arrow & left button down
  72. BOOL m_bMouseDownArrowLeft; // TRUE = mouse over left arrow & left button down
  73. BOOL m_bMouseDownArrowUp; // TRUE = mouse over left arrow & left button down
  74. BOOL m_bMouseDownArrowDown; // TRUE = mouse over right arrow & left button down
  75. BOOL m_bMouseDown; // TRUE = mouse over thumb & left button down
  76. BOOL m_bDragging; // TRUE = thumb is being dragged
  77. BOOL m_bHorizontal; // TRUE = horizontal scroll bar
  78. void Draw();
  79. void DrawHorizontal();
  80. void DrawVertical();
  81. void LimitThumbPosition();
  82. void SetDefaultCursor();
  83. void SetPositionFromThumb();
  84. void UpdateThumbPosition();
  85. // Generated message map functions
  86. protected:
  87. //{{AFX_MSG(CXScrollBar)
  88. afx_msg void OnPaint();
  89. afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  90. afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  91. afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  92. afx_msg void OnTimer(UINT nIDEvent);
  93. afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
  94. //}}AFX_MSG
  95. DECLARE_MESSAGE_MAP()
  96. };
  97. /////////////////////////////////////////////////////////////////////////////
  98. //{{AFX_INSERT_LOCATION}}
  99. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  100. #endif //XSCROLLBAR_H