贴一个CMemDC 代码,这东西真不错噢,短小精悍,可谓极品

罗索客 发布于 2006-11-28 21:53 点击:3941次 

来自:

原文: http://yuantao82.spaces.live.com/Blog/cns!8FC0A772D812A22F!139.entry?owner=1 #ifndef _MEMDC_H_ #define _MEMDC_H_ ////////////////////////////////////////////////// // CMemDC - memory DC // // Author: Keith Rule // Email: keithr@europa.com //

TAG: 封装类  CMemDC  

 

原文:http://yuantao82.spaces.live.com/Blog/cns!8FC0A772D812A22F!139.entry?owner=1

#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 accidentally 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

(iwgh)

 

本站文章除注明转载外,均为本站原创或编译欢迎任何形式的转载,但请务必注明出处,尊重他人劳动,同学习共成长。转载请注明:文章转载自:罗索实验室 [http://www.rosoo.net/a/200611/6425.html]

 

时间: 2024-09-03 19:44:54

贴一个CMemDC 代码,这东西真不错噢,短小精悍,可谓极品的相关文章

今天找到的一个站点,有些东西还不错,学习笔记

程式設計 這裡是我對於一些程式設計的學習紀錄,主要是紀錄一些我感興趣的事物和一些介紹. Database SQLite PostgreSQL C/C++ wxWidgets SDL TinyXML Tcl/Tk C# and dotNET  Windows IME 安裝 libogg 和 libvorbis X and Unix XIM 

process-请大家帮我看看两段代码的区别真想不明白了

问题描述 请大家帮我看看两段代码的区别真想不明白了 有两段代码 代码一是单独写成函数来调用的, 我把他们合成一个主函数的代码 就出错 ?好像是变量递增的问题,我怎么也想不通,麻烦大家了. 代码一 ?别人写的: #include #include #include #include #pragma comment(lib,"Psapi.lib") int FindModules( DWORD processID ) { ? ? HMODULE hMods[1024]; ? ? HANDL

class-请教一个java代码的问题有点看不懂

问题描述 请教一个java代码的问题有点看不懂 如下 abstract public class SafeAction extends Action { protected Log log = LogFactory.getLog(this.getClass()); private static final String CONTENT_TYPE = "text/html; charset=GBK"; private TblConTxnLog tblConTxnLog = null; a

css百度分享-请高手帮改一个CSS代码 让百度分享和文章链接并排

问题描述 请高手帮改一个CSS代码 让百度分享和文章链接并排 .Article-Tool{ border:1px solid #c3d4e7; position:relative; top:-1px; text-align:right; padding:8px; vertical-align:middle; height:15px; background-color:#f4f8fd} .Article-Tool a{width:16px;height:16px;line-height:16px;

我,一个写代码的 程序员 感悟_励志篇

前几天一个朋友给我的blog留言,谈到希望在新年里能够看到的不仅仅是我对技术的分享,更希望能够看到对于技术学习.职业发展的规划.因此想到了写一点什么分享一下自己这些年的一点点"收获",周星驰的喜剧之王里面说到他是一个演员(虽然被叫做跑龙套的),我想我,就一个写代码的. 爱这行        从事任何行业都一样,只有真正的爱上了这份工作,才会投入热情,才会在顺境中自我警醒,在逆境中寻找突破.这个行业的竞争很激烈,你停下来走,别人就立刻会跑步超过你,没有对这一行业的一种热情,就很难在困境中

Android 如何添加一个apk使模拟器和真机都编译进去

  添加一个apk都需要将LOCAL_PACKAGE_NAME的值添加到PRODUCT_PACKAGES才行. 而PRODUCT_PACKAGES一般在build/target/product/目录下的文件里都有定义 1. 编译模拟器时,会将以下文件中的PRODUCT_PACKAGES定义的apk都编译进去 build/target/product/banyan_addon.mk build/target/product/sdk.mk sdk/build/product_sdk.mk devel

Android如何添加一个apk使模拟器和真机都编译进去

  添加一个apk都需要将LOCAL_PACKAGE_NAME的值添加到PRODUCT_PACKAGES才行. 而PRODUCT_PACKAGES一般在build/target/product/目录下的文件里都有定义 1. 编译模拟器时,会将以下文件中的PRODUCT_PACKAGES定义的apk都编译进去 build/target/product/banyan_addon.mk build/target/product/sdk.mk sdk/build/product_sdk.mk devel

按下回车键指向下一个位置的一个函数代码

 本篇文章主要是对按下回车键指向下一个位置的一个函数代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助  代码如下: function tofocus(itemname)    //按回车置下一个位置          {              var a              a=eval("document.vouch."+itemname)              a.focus()          }  在控件中使用onkeypress="jav

我想做一个这样新用户注册界面,可是我不会把权限和姓名也写进数据库,求好心人赐一个完整代码

问题描述 我想做一个这样新用户注册界面,可是我不会把权限和姓名也写进数据库,求好心人赐一个完整代码 解决方案 看看这些http://download.csdn.net/detail/aimonhai/1480222http://download.csdn.net/download/bkzhw3/5975209http://download.csdn.net/download/fanhongwei601/4353841http://download.csdn.net/detail/qq223857