⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flicker_free_drawing.shtml.htm

📁 mfc资料集合5
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <TITLE>Miscellaneous - Flicker free drawing using memory DC</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><A HREF="http://209.66.99.126/cgi/ads.cgi?advert=catalyst"><IMG SRC="../banners/catalyst.jpg" tppabs="http://www.codeguru.com/banners/catalyst.jpg" HEIGHT=60 WIDTH=468 ALT="Catalyst Development" BORDER=2></A><BR><SMALL><A HREF="http://209.66.99.126/cgi/ads.cgi?advert=catalyst">Click here for Free ActiveX Control</A></SMALL><td>
</tr>
</table>


<CENTER>
<H3>
<FONT COLOR="#AOAO99">Flicker free drawing using memory DC</FONT></H3></CENTER>

<CENTER>
<H3>

<HR></H3></CENTER>

<p>This article was contributed by <A HREF="mailto:keithr@europa.com">Keith Rule</A>. 
<br><a href="memdc.zip" tppabs="http://www.codeguru.com/misc/memdc.zip">Download</a> a sample file. The zip file is 17KB.


<h3>Flicker Free Updates Using CMemDC</h3>
Creating an MS-Windows application is often an absorbing task. Many issues are often postponed
 until near the end of development. One commonly postponed issue is removing flicker from screen 
 redraws. This short tip explains how to do this using the CMemDC class with MFC. This 
 class isn't a part of MFC, but after you've seen how useful it is you may add it to your MFC toolbox.


<h4>Exacerbating the Problem</h4>
One of the best ways to exacerbate flickering is to enable the "Show windows contents while dragging" mode found in the Plus! Tab of the Display properties in Windows 95. This mode causes your application to be redrawn while it is resized. 
<p><img src="flicker_free_drawing.gif" tppabs="http://www.codeguru.com/misc/flicker_free_drawing.gif" width="529" height="504"></p>
Windows NT also has a similar mode that may be set. If you enable this mode and your application flashes or flicker when resized this tip will probably help.


<h4>A Simple Solution</h4>
The reason your application is flickering is that the original image is being erased and then redrawn in quick succession when the application is resized. A common technique to reduce or eliminate this problem is to not erase the image, but rather, to draw to an off screen buffer and BitBliting the buffer to the screen. This eliminates the flashing caused by erasing, and the flashing cause by being able to see individual drawing operations on the screen. 
To disable erasing you need to intercept the WM_ERASEBKGND message and return FALSE.

<PRE><TT><FONT COLOR="#990000">BOOL CNoFlickerView::OnEraseBkgnd(CDC* pDC) 
{
	return FALSE;
}
</FONT></TT></PRE>

To draw to an off screen buffer you need to create a memory CDC, draw to it, and BitBlit the result to the screen. You can do this by using the CMemDC class. This class is very small, just a few lines, but it makes handles most of the off screen drawing issues.

<PRE><TT><FONT COLOR="#990000">
#ifndef _MEMDC_H_
#define _MEMDC_H_

//////////////////////////////////////////////////
// CMemDC - memory DC
//
// Author: Keith Rule
// Email:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -