AUTOSCROLLVIEW.CPP
资源名称:SNMP范例源代码.zip [点击查看]
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:4k
源码类别:
SNMP编程
开发平台:
MultiPlatform
- // AutoScrollView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OAM.h"
- #include "AutoScrollView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAutoScrollView
- IMPLEMENT_DYNCREATE(CAutoScrollView, CScrollView)
- CAutoScrollView::CAutoScrollView()
- {
- m_bIsScrolling = FALSE;
- }
- CAutoScrollView::~CAutoScrollView()
- {
- }
- BEGIN_MESSAGE_MAP(CAutoScrollView, CScrollView)
- //{{AFX_MSG_MAP(CAutoScrollView)
- ON_WM_LBUTTONDOWN()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAutoScrollView drawing
- void CAutoScrollView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- void CAutoScrollView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CAutoScrollView diagnostics
- #ifdef _DEBUG
- void CAutoScrollView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CAutoScrollView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CAutoScrollView message handlers
- void CAutoScrollView::AutoScrollView(UINT nRefMessage)
- {
- HCURSOR hCur;
- hCur = AfxGetApp()->LoadCursor(IDC_HANDCUR);//AFX_IDC_HSPLITBAR);
- SetCursor(hCur);
- m_bIsScrolling = TRUE;
- MSG msg;
- CPoint ptScrollPos;
- CPoint ptDevScrollPos;
- CPoint ptCursorPos;
- CRect rc;
- long dx,dy;
- SIZE sizeTotal;
- SIZE sizePage;
- SIZE sizeLine;
- int nMapMode;
- int nMapFactor;
- int xMin,xMax;
- int yMin,yMax;
- /////
- CPoint ptOldCursorPos;
- GetCursorPos(&ptOldCursorPos);
- ScreenToClient(&ptOldCursorPos);
- /////
- msg.message = 0;
- SetCapture();
- GetDeviceScrollSizes(nMapMode,sizeTotal,sizePage,sizeLine);
- GetScrollRange(SB_HORZ,&xMin,&xMax);
- GetScrollRange(SB_VERT,&yMin,&yMax);
- while(msg.message != nRefMessage)
- {
- if(PeekMessage(&msg,0,0,0,PM_REMOVE))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- if(msg.message != WM_MOUSEMOVE)
- continue;
- ptScrollPos = GetScrollPosition();
- ptDevScrollPos = GetDeviceScrollPosition();
- GetCursorPos(&ptCursorPos);
- ScreenToClient(&ptCursorPos);
- GetClientRect(&rc);
- dx = 0l;
- dy = 0l;
- //////////////
- dx = ptOldCursorPos.x - ptCursorPos.x;
- if(dx < 0 && sizeTotal.cx <= rc.Width())
- dx = 0;
- else if(dx > 0 && (ptDevScrollPos.x < xMin || sizeTotal.cx <= rc.Width()))
- dx = 0;
- dy = ptOldCursorPos.y - ptCursorPos.y;
- if(dy < 0 && sizeTotal.cy <= rc.Height())
- dy = 0;
- else if(dy > 0 && (ptDevScrollPos.y < yMin || sizeTotal.cy <= rc.Height()))
- dy = 0;
- ptOldCursorPos = ptCursorPos;
- //////////////
- /*
- if((ptCursorPos.y<0)&&(ptDevScrollPos.y != yMin))
- dy = min(-sizeLine.cy,max(-sizePage.cy,
- (ptCursorPos.y/10)*sizeLine.cy));
- else if ((ptCursorPos.y>rc.bottom)&&(ptDevScrollPos.y!=yMax))
- dy = max(sizeLine.cy,min(sizePage.cy,
- ((ptCursorPos.y-rc.bottom)/10)*sizeLine.cy));
- if((ptCursorPos.x<0)&&(ptDevScrollPos.x != xMin))
- dx = min(-sizeLine.cx,max(-sizePage.cx,
- (ptCursorPos.x/10)*sizeLine.cx));
- else if ((ptCursorPos.x>rc.right)&&(ptDevScrollPos.x!=xMax))
- dx = max(sizeLine.cx,min(sizePage.cx,
- ((ptCursorPos.x-rc.right)/10)*sizeLine.cx));
- */
- //////////////////////
- if((dx != 0)||(dy != 0))
- {
- nMapFactor = (nMapMode == MM_TEXT)?1:-1;
- ptScrollPos.y += (int)dy*nMapFactor;
- ptScrollPos.x += (int)dx;
- // m_bIsScrolling = TRUE;
- // OnAutoScroll(ptCursorPos,TRUE);
- ScrollToPosition(ptScrollPos);
- // OnAutoScroll(ptCursorPos,FALSE);
- }
- else
- {
- // m_bIsScrolling = FALSE;
- }
- }
- ReleaseCapture();
- m_bIsScrolling = FALSE;
- }
- void CAutoScrollView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- AutoScrollView(WM_LBUTTONUP);
- CScrollView::OnLButtonDown(nFlags, point);
- }