ScrollWndbase.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:5k
源码类别:
P2P编程
开发平台:
Visual C++
- // ScrollWndbase.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "ScrollWndbase.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define SB_LINEDOWN_WHEEL 10
- #define SB_LINEUP_WHEEL 11
- /////////////////////////////////////////////////////////////////////////////
- // CScrollWndbase
- CScrollWndbase::CScrollWndbase(const CRect rc)
- {
- m_ptTopLeft = CPoint(0, 0);
- m_rect = rc;
- m_curRect = CRect(0, 0, 0, 0);
- }
- CScrollWndbase::~CScrollWndbase()
- {
- }
- BEGIN_MESSAGE_MAP(CScrollWndbase, CWnd)
- //{{AFX_MSG_MAP(CScrollWndbase)
- ON_WM_HSCROLL()
- ON_WM_VSCROLL()
- ON_WM_SIZE()
- ON_WM_MOUSEWHEEL()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CScrollWndbase message handlers
- void CScrollWndbase::ResetPos()
- {
- OnVScroll(SB_THUMBPOSITION, 0, 0);
- OnHScroll(SB_THUMBPOSITION, 0, 0);
- }
- CPoint CScrollWndbase::GetTopLeft() const
- {
- return m_ptTopLeft;
- }
- CRect CScrollWndbase::GetRect() const
- {
- return m_rect;
- }
- void CScrollWndbase::OnScrollEx()
- {
- }
- void CScrollWndbase::OnSize(UINT nType, int cx, int cy)
- {
- CWnd::OnSize(nType, cx, cy);
- m_curRect = CRect(0, 0, cx, cy);
- int nScrollMax;
- if (cy < m_rect.Height())
- {
- nScrollMax = m_rect.Height(); //- cy;
- }
- else
- nScrollMax = 0;
- long newpos = m_ptTopLeft.y;
- if (newpos > (m_rect.Height() - cy))
- {
- newpos = m_rect.Height() - cy;
- if (newpos < 0) newpos = 0;
- // ScrollWindow(0, newpos);
- }
- SCROLLINFO si;
- si.cbSize = sizeof(SCROLLINFO);
- si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
- si.nMin = 0;
- si.nMax = nScrollMax;
- si.nPage = cy;
- si.nPos = 0;
- SetScrollInfo(SB_VERT, &si, TRUE);
- if (cx < m_rect.Width())
- {
- nScrollMax = m_rect.Width();// - cx;
- }
- else
- nScrollMax = 0;
- si.cbSize = sizeof(SCROLLINFO);
- si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
- si.nMin = 0;
- si.nMax = nScrollMax;
- si.nPage = cx;
- si.nPos = 0;
- SetScrollInfo(SB_HORZ, &si, TRUE);
- m_ptTopLeft = CPoint(0, 0);
- OnScrollEx();
- }
- void CScrollWndbase::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- int nDelta;
- int nMaxPos = m_rect.Width() - m_curRect.Width();
- if (nMaxPos <= 0) return;
- switch (nSBCode)
- {
- case SB_LINEDOWN:
- if (m_ptTopLeft.x >= nMaxPos)
- return;
- nDelta = min(nMaxPos/10, nMaxPos - m_ptTopLeft.x);
- break;
- case SB_LINEUP:
- if (m_ptTopLeft.x <= 0)
- return;
- nDelta = -min(nMaxPos/10, m_ptTopLeft.x);
- break;
- case SB_PAGEDOWN:
- if (m_ptTopLeft.x >= nMaxPos)
- return;
- nDelta = min(m_curRect.Width(), nMaxPos-m_ptTopLeft.x);
- break;
- case SB_PAGEUP:
- if (m_ptTopLeft.x <= 0)
- return;
- nDelta = -min(m_curRect.Width(), m_ptTopLeft.x);
- break;
- case SB_THUMBPOSITION:
- nDelta = (int)nPos - m_ptTopLeft.x;
- break;
- case SB_THUMBTRACK:
- nDelta = (int)nPos - m_ptTopLeft.x;
- break;
- default:
- return;
- }
- m_ptTopLeft.x += nDelta;
- SetScrollPos(SB_HORZ, m_ptTopLeft.x, TRUE);
- OnScrollEx();
- CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
- }
- void CScrollWndbase::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- int nDelta;
- int nMaxPos = m_rect.Height() - m_curRect.Height();
- if (nMaxPos <= 0) return;
- switch (nSBCode)
- {
- case SB_LINEDOWN_WHEEL :
- {
- if (m_ptTopLeft.y >= nMaxPos)
- return;
- if ((nMaxPos - m_ptTopLeft.y) < 0)
- {
- assert(false);
- return;
- }
- nDelta = min(30, nMaxPos - m_ptTopLeft.y);
- }
- break;
- case SB_LINEUP_WHEEL:
- if (m_ptTopLeft.y <= 0)
- return;
- nDelta = -min(30, m_ptTopLeft.y);
- break;
- case SB_LINEDOWN:
- if (m_ptTopLeft.y >= nMaxPos)
- return;
- nDelta = min(nMaxPos/10, nMaxPos - m_ptTopLeft.y);
- break;
- case SB_LINEUP:
- if (m_ptTopLeft.y <= 0)
- return;
- nDelta = -min(nMaxPos/10, m_ptTopLeft.y);
- break;
- case SB_PAGEDOWN:
- if (m_ptTopLeft.y >= nMaxPos)
- return;
- nDelta = min(m_curRect.Height(), nMaxPos - m_ptTopLeft.y);
- break;
- case SB_PAGEUP:
- if (m_ptTopLeft.y <= 0)
- return;
- nDelta = -min(m_curRect.Height(), m_ptTopLeft.y);
- break;
- case SB_THUMBPOSITION:
- nDelta = (int)nPos - m_ptTopLeft.y;
- break;
- case SB_THUMBTRACK:
- nDelta = (int)nPos - m_ptTopLeft.y;
- break;
- default:
- return;
- }
- m_ptTopLeft.y += nDelta;
- SetScrollPos(SB_VERT, m_ptTopLeft.y,TRUE);
- OnScrollEx();
- CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
- }
- BOOL CScrollWndbase::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
- {
- OnVScroll(zDelta > 0 ? SB_LINEUP_WHEEL : SB_LINEDOWN_WHEEL , 0, 0);
- return CWnd::OnMouseWheel(nFlags, zDelta, pt);
- }