📄 cachedscrollview.cpp
字号:
// 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);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -