MemDC.h
#ifndef _MEMDC_H_ #define _MEMDC_H_ ////////////////////////////////////////////////// // CMemDC - memory DC // // Author: Keith Rule // Email: keithr@europa.com // Copyright 1996-2002, 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. - KR // // 11/3/99 Fixed most common complaint. Added // background color fill. - KR // // 11/3/99 Added support for mapping modes other than // MM_TEXT as suggested by Lee Sang Hun. - KR // // 02/11/02 Added support for CScrollView as supplied // by Gary Kirkham. - KR // // This class implements a memory Device Context which allows // flicker free drawing. class CMemDC : public CDC { private: CBitmap m_bitmap; // Offscreen bitmap CBitmap* m_oldBitmap; // 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. public: CMemDC(CDC* pDC, const CRect* pRect = NULL) : CDC() { ASSERT(pDC != NULL); // Some initialization m_pDC = pDC; m_oldBitmap = NULL; m_bMemDC = !pDC->IsPrinting(); // Get the rectangle to draw if (pRect == NULL) { pDC->GetClipBox(&m_rect); } else { m_rect = *pRect; } if (m_bMemDC) { // Create a Memory DC CreateCompatibleDC(pDC); pDC->LPtoDP(&m_rect); m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); m_oldBitmap = SelectObject(&m_bitmap); SetMapMode(pDC->GetMapMode()); SetWindowExt(pDC->GetWindowExt()); SetViewportExt(pDC->GetViewportExt()); pDC->DPtoLP(&m_rect); 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; } // Fill background FillSolidRect(m_rect, pDC->GetBkColor()); } ~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_oldBitmap); } 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; } }; #endif
MemDC.cpp
#include "stdafx.h" #include "MemDC.h"
相关推荐
1、双缓冲绘图技术概述 原理:将一般的在CDC中绘图改成在一内存设备中绘图(CDC型变量,一般命名为pMemDC),然后使用BitBlt()函数将pMemDC中的图像复制到CDC中; 步骤: ①创建内存设备CDC *pMemDC;关联设备...
MFC自定义的双缓冲DC封装类,简洁易用,自己编写的,大型项目中提取
MFC 双缓冲绘图 圆球在屏幕中移动的动画,碰到边框反弹,解决了闪烁的问题
MFC 双缓冲小实例 实现了画图版的画笔功能 还有一些其他小功能 主要是应用了双缓冲进行图片的刷新
运用mfc双缓冲技术实现几何图形沿着指定的曲线移动,代码中包含多边形图形绘制代码,包含双缓冲绘图代码还有图形移动功能实现
MFC编写的类似于资源管理器界面的实时显示曲线的程序。
使用MFC文档视图结构,采用双缓冲绘图技术写的gdi绘图程序
为防止高速刷新造成的屏幕闪烁问题,可以使用双缓冲技术。本文介绍了为使用双缓冲需要添加的代码,可以直接使用。
MFC利用双缓冲技术在IDC_STATIC上绘制图像
MFC双缓冲避免闪屏实现机制,初学者入门必备,介绍很详细。
这是一个MFC综合的小实例程序 包括了鼠标画图 颜色选择 双缓冲贴图
自己做的,大家可以看看!做来瞎玩的!嘿嘿~!~~~~~~~~~~~~~
MFC双缓冲显示可视化界面
这是一个关于最短路径的搜索,并用MFC的界面显示出来,其中显示用了缓冲,速度经过了优化,不闪屏。界面做的很可爱。。。
MFC双缓冲绘图,正弦波移动,适合工控数据采集.
双缓冲:解决的是多层刷新,一个简单的文件头,解决。
MFC Excel类封装成库DLL(在静态库中使用 MFC),将 Excel类打包成库文件,对外留几个接口,使用方便
类似MFC对win32 api的封装,但是功能较弱,仅对消息处理进行了封装。原理上用c++作了简单封装,用mingw单窗口单消息过程,该程序通过,其余的未测试
本程序利用双缓冲,在MFC中移动图形,通过↑、↓、←、→四个按键,控制图形移动方向,实现无闪烁移动图形的目的。