ScrollHelper.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Filename: ScrollHelper.h
  2. // S.Chan, 01 Jul 2005
  3. #ifndef SCROLL_HELPER_INCLUDED
  4. #define SCROLL_HELPER_INCLUDED
  5. #if _MSC_VER > 1000
  6. #pragma once
  7. #endif // _MSC_VER > 1000
  8. class CScrollHelper
  9. {
  10. public:
  11. CScrollHelper();
  12. ~CScrollHelper();
  13. // Attach/detach a CWnd or CDialog.
  14. void AttachWnd(CWnd* pWnd);
  15. void DetachWnd();
  16. // Set/get the virtual display size. When the dialog or window
  17. // size is smaller than the display size, then that is when
  18. // scrollbars will appear. Set either the display width or display
  19. // height to zero if you don't want to enable the scrollbar in the
  20. // corresponding direction.
  21. void SetDisplaySize(int displayWidth, int displayHeight);
  22. const CSize& GetDisplaySize() const;
  23. // Get current scroll position. This is needed if you are scrolling
  24. // a custom CWnd which implements its own drawing in OnPaint().
  25. const CSize& GetScrollPos() const;
  26. // Get current page size. Useful for debugging purposes.
  27. const CSize& GetPageSize() const;
  28. // Scroll back to top, left, or top-left corner of the window.
  29. void ScrollToOrigin(bool scrollLeft, bool scrollTop);
  30. // Message handling.
  31. void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  32. void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  33. BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
  34. BOOL OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
  35. void OnSize(UINT nType, int cx, int cy);
  36. private:
  37. int Get32BitScrollPos(int bar, CScrollBar* pScrollBar);
  38. void UpdateScrollInfo();
  39. void UpdateScrollBar(int bar, int windowSize, int displaySize,
  40. LONG& pageSize, LONG& scrollPos, LONG& deltaPos);
  41. CWnd* m_attachWnd;
  42. CSize m_pageSize;
  43. CSize m_displaySize;
  44. CSize m_scrollPos;
  45. };
  46. #endif // SCROLL_HELPER_INCLUDED
  47. // END