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