CachedScrollView.cpp
资源名称:08.zip [点击查看]
上传用户:ynjin1970
上传日期:2014-10-13
资源大小:6438k
文件大小:3k
源码类别:
中间件编程
开发平台:
Visual C++
- // CachedScrollView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "CCachedScrollViewP.h"
- #include "CachedScrollView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCachedScrollView
- IMPLEMENT_DYNCREATE(CCachedScrollView, CScrollView)
- CCachedScrollView::CCachedScrollView()
- { CacheValid=FALSE;
- CacheRect=new CRect;
- CacheRect.SetRectEmpty();
- }
- CCachedScrollView::~CCachedScrollView()
- {
- }
- BEGIN_MESSAGE_MAP(CCachedScrollView, CScrollView)
- //{{AFX_MSG_MAP(CCachedScrollView)
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCachedScrollView drawing
- void CCachedScrollView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- void CCachedScrollView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCachedScrollView diagnostics
- #ifdef _DEBUG
- void CCachedScrollView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CCachedScrollView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CCachedScrollView message handlers
- void CCachedScrollView::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- OnPrepareDC(&dc);
- //无缓冲
- if (CacheRect.IsRectNull())
- {
- OnDraw(&dc);
- return;
- }
- //创建缓冲位图
- if (CacheBitmap.m_hObject==NULL)
- CacheBitmap.CreateCompatibleBitmap(&dc,CacheRect.Width(),CacheRect.Height());
- CRect ClientRect;
- GetClientRect(ClientRect);
- CPoint org=dc.GetViewportOrg();
- ClientRect.OffsetRect(-org.x,-org.y);
- if (!CacheRect.PtInRect(ClientRect.TopLeft()) ||
- !CacheRect.PtInRect(ClientRect.BottomRight()))
- {
- CacheRect.OffsetRect(
- ClientRect.CenterPoint()-CacheRect.CenterPoint());
- CacheValid=FALSE;
- }
- CDC mdc;
- mdc.CreateCompatibleDC(&dc);
- mdc.SelectObject(&CacheBitmap);
- if (!CacheValid) {
- mdc.SelectStockObject(WHITE_BRUSH);
- mdc.SelectStockObject(NULL_PEN);
- mdc.Rectangle(0,0,CacheRect.Width(),CacheRect.Height());
- mdc.SelectStockObject(BLACK_PEN);
- mdc.SetViewportOrg(-CacheRect.left,-CacheRect.top);
- OnDraw(&mdc);
- mdc.SetViewportOrg(0,0);
- CacheValid=TRUE;
- }
- dc.SelectClipRgn(NULL);
- dc.BitBlt(CacheRect.left,CacheRect.top,
- CacheRect.Width(),CacheRect.Height(),&mdc,0,0,SRCCOPY);
- }