mailao
日历
网志分类
· 所有网志 (183)
· 我乱写的 (3)
· Graphics & Engine (4)
· Learn DFA (112)
· 抄的 (60)
· 未分类 (4)
站内搜索
友情链接
· 我的歪酷 非非共享界

订阅 RSS

0071866

歪酷博客

不超越惰性的防线,信念将在彷徨中夭折。
« 上一篇: MFC MDI 关于CWinApp::OpenDocumentFile 下一篇: cvConvertImage opencv 图象 倒置 »
mailao @ 2007-08-06 11:38

这个在网上找的,希望对大家有用!


#ifndef _MEMDC_H_
//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email:   keithr@europa.com
// Copyright 1996-1997, Keith Rule
//
// You may freely use or modify this code provided this
// Copyright is included in all derived versions.
//
// History - 10/3/97 Fixed scrolling bug.
//             Added print support.
//
// This class implements a memory Device Context

class CMemDC : public CDC
{
public:

 // constructor sets up the memory DC
 CMemDC(CDC* pDC) : CDC()
 {
  ASSERT(pDC != NULL);

  m_pDC = pDC;
  m_pOldBitmap = NULL;
  m_bMemDC = !pDC->IsPrinting();

  if (m_bMemDC)   // Create a Memory DC
  {
   pDC->GetClipBox(&m_rect);
   CreateCompatibleDC(pDC);
   m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
   m_pOldBitmap = SelectObject(&m_bitmap);
   SetWindowOrg(m_rect.left, m_rect.top);
  }
  else       // Make a copy of the relevent parts of the current DC for printing
  {
   m_bPrinting = pDC->m_bPrinting;
   m_hDC     = pDC->m_hDC;
   m_hAttribDC = pDC->m_hAttribDC;
  }
 }

 // Destructor copies the contents of the mem DC to the original DC
 ~CMemDC()
 {
  if (m_bMemDC)  
  {    
   // Copy the offscreen bitmap onto the screen.
   m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
    this, m_rect.left, m_rect.top, SRCCOPY);

   //Swap back the original bitmap.
   SelectObject(m_pOldBitmap);
  } else {
   // All we need to do is replace the DC with an illegal value,
   // this keeps us from accidently deleting the handles associated with
   // the CDC that was passed to the constructor.
   m_hDC = m_hAttribDC = NULL;
  }
 }

 // Allow usage as a pointer
 CMemDC* operator->() {return this;}

 // Allow usage as a pointer
 operator CMemDC*() {return this;}

private:
 CBitmap   m_bitmap;     // Offscreen bitmap
 CBitmap* m_pOldBitmap;   // bitmap originally found in CMemDC
 CDC*     m_pDC;       // Saves CDC passed in constructor
 CRect   m_rect;       // Rectangle of drawing area.
 BOOL     m_bMemDC;     // TRUE if CDC really is a Memory DC.
};

#endif 


另外注意:
  使用时将   OnDraw()   里面的   CDC   参数换到这个就行了,另外还要重载OnEraseBkgnd函数,令其返回   FALSE   就可以了  
  BOOL   CMyView::OnEraseBkgnd(CDC*   pDC)    
  {  
  return   FALSE;      
  }
  




最新评论

2007-08-06 11:45 网址: http://mailao.ycool.com/

嗯...应该算是对双缓存一个简单模拟....


评论 / 个人网页 / 扔小纸条
* 昵称

已经注册过? 请登录

新用户请先注册 以便能显示头像及追踪评论回复

Email
网址
* 评论
表情
 


 

分类小组论坛
杂谈 , 娱乐、八卦 , 文学、艺术 , 体育 , 旅游、同城 , 象牙塔 , 情感 , 时尚、生活 , 星座 , 科技

请注意遵守中华人民共和国法律法规, 如威胁到本站生存, 将依法向有关部门报告, 同时本站的相关记录可能成为对您不利的证据.

相关法律法规
全国人大常委会关于维护互联网安全的决定
中华人民共和国计算机信息系统安全保护条例
中华人民共和国计算机信息网络国际联网管理暂行规定
计算机信息网络国际联网安全保护管理办法
计算机信息系统国际联网保密管理规定