有段代码看不明白,谁能给解释清楚,谢谢

willwl 2005-05-17 05:24:38
这段代码究竟实现了什么功能,越详细越好,因为要用这个类,可我看不明白怎么用

#ifndef _MEMDC_H_
#define _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.
//
// This class implements a memory Device Context

class CMyMemDC : public CDC {
private:
CBitmap* m_bitmap;
CBitmap* m_oldBitmap;
CDC* m_pDC;
CRect m_rcBounds;
public:
CMyMemDC(CDC* pDC, const CRect& rcBounds) : CDC()
{
CreateCompatibleDC(pDC);
m_bitmap = new CBitmap;
m_bitmap->CreateCompatibleBitmap(pDC, rcBounds.Width(), rcBounds.Height());
m_oldBitmap = SelectObject(m_bitmap);
m_pDC = pDC;
m_rcBounds = rcBounds;
}
~CMyMemDC()
{
m_pDC->BitBlt(m_rcBounds.left, m_rcBounds.top, m_rcBounds.Width(), m_rcBounds.Height(),
this, m_rcBounds.left, m_rcBounds.top, SRCCOPY);
SelectObject(m_oldBitmap);
if (m_bitmap != NULL) delete m_bitmap;
}
CMyMemDC* operator->() {
return this;
}
};

#endif
...全文
81 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanqing 2005-05-18
  • 打赏
  • 举报
回复
不就是把图片画到m_pDC所在的子窗口上吗.
littlefellow 2005-05-18
  • 打赏
  • 举报
回复
自动进行后台缓冲的绘图环境类
hell_wolf 2005-05-17
  • 打赏
  • 举报
回复
up
younggle 2005-05-17
  • 打赏
  • 举报
回复
这是继承了CDC的类,在析构的时候进行内存拷贝,比CDC省略了一点。这个类只能用来声明局部变量。
下面的代码用来填充背景:
RECT rect;
memset(&rect, 0, sizeof(RECT));
this->GetClientRect(&rect);

CMyMemDC memdc(pDC, rect);

CBrush m_Brush;
m_Brush.CreateSolidBrush(RGB(16, 154, 148));
memdc->FillRect(&rect, &m_Brush);
pomelowu 2005-05-17
  • 打赏
  • 举报
回复
构造函数把this对象创建为pDC的兼容DC,选入位图,得到大小,保存pDC指针
析构函数中把this对象的DC上的内容复制到构造函数传入的pDC中。

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧