双缓冲为什么应该这样用?
来源:互联网 发布:带-域名 编辑:程序博客网 时间:2024/06/01 21:07
看了很多的使用双缓冲的例子。有的时候也知道是应该那样用,原理也知道一点,但就是写不出来,为何?
脑子里面没正确的概念,有的只是个皮毛,现在虽然不完全明白。仅就把所知道的写下来,与诸君一同学习。
先上代码:
void CXXXWnd::OnPaint(){CPaintDC dc(this);CDC memDC;memDC.CreateCompatibleDC(&dc);CRect rect;GetClientRect(rect);CBitmap bm;bm.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());memDC.SelectObject(&bm);memDC.SetBkMode(TRANSPARENT);memDC.FillSolidRect(rect, RGB(128,128,0));dc.BitBlt(0,0,rect.Width(),rect.Height(), &memDC, 0, 0, SRCCOPY);}
这里定义为CDC memDC,并创建兼容DC。
同理也创建一个兼容源DC的CBitmap。
在内存DC画图,将该DC内容画到实际DC上。
借鉴MSDN双缓冲步骤:
Remarks
A memory device context is a device context that exists only in memory. When the memory device context is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high.
Before an application can use a memory device context for drawing operations, it must select a bitmap of the correct width and height into the device context. This may be done by usingCreateCompatibleBitmap to specify the height, width, and color organization required in the function call.
When a memory device context is created, all attributes are set to typical default values. The memory device context can be use as a typical device context. You can set the attributes to non-default values, obtain the current setting of its attributes, and select pens, brushes and regions into it.
The CreateCompatibleDC function can only be used with devices that support raster operations. An application can determine whether a device supports these operations by calling theGetDeviceCaps function.
When you no longer need the memory device context, call the DeleteDC function to delete it.
- 双缓冲为什么应该这样用?
- 应该这样。。。。。
- 应该这样
- 个推你应该这样用的
- 个推你应该这样用的
- 个推你应该这样用的
- 个推你应该这样用的
- 个推你应该这样用的
- 个推你应该这样用的
- 个推你应该这样用的
- Java学习笔记--------为什么不能这样用???
- 男人,应该这样做!!
- 也许应该这样做
- 不应该这样子
- 男人应该这样做
- 初学者应该这样看盘
- 男人,应该这样做!!
- 我们应该这样
- 逆波兰式--利用栈实现
- ASP.NET页面同时存在自定义控件,母版页,内容页的加载顺序
- 突破伪静态的四种注入方法
- FlashFxp中文乱码解决
- 盘点2011年度四大艳照门事件
- 双缓冲为什么应该这样用?
- 一维最接近点对的分治解法
- 利用ZooKeeper的Java API来创建一个znode
- php文件上传类
- 系统设计时应尽量避免出现left outer join, right outer join
- C# 上传附件 删除附件
- CButtonST的应用
- php生成缩微图类
- WWW的工作原理