MFC双缓冲

16 篇文章 0 订阅
<span style="font-size:14px;">绘图的过程放在OnDraw或者OnPaint函数中,OnPaint在进行屏幕显示时调用OnDraw。</span>
<span style="font-size:14px;">作图时发生闪烁的原因:</span>
<span style="font-size:14px;">当窗口需要重绘时,首先用背景色清除显示区,然后调用OnPaint,短时间内背景色与显示图像交替出现,使得显示窗口看起来在闪烁。</span>
<span style="font-size:14px;">将背景刷设置为NULL,重绘图形不会闪烁,但是窗口的显示会混乱。</span>
<span style="font-size:14px;">解决方案:</span>
<span style="font-size:14px;">MFC双缓冲:</span><span style="font-size:14px;"><span style="font-family:Tahoma;color:#555555;text-align: left; text-transform: none; line-height: 20px !important; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-break: normal; word-wrap: normal; widows: 1; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;"><span style="line-height: 20px !important; word-break: normal; word-wrap: normal;">把要显示的图形先在内存中</span></span><span style="font-family:Tahoma;color:#555555;text-align: left; text-transform: none; line-height: 20px !important; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; word-break: normal; word-wrap: normal; widows: 1; background-color: rgb(255, 255, 255); -webkit-text-stroke-width: 0px;"><span style="line-height: 20px !important; word-break: normal; word-wrap: normal;">绘制好,然后再一次性的将内存中的图形按照一个点一个点地覆盖到屏幕上去</span></span></span>
void CDrawPicView::OnDraw(CDC* pDC)
{
	CDrawPicDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	CRect rect = 0;
	GetClientRect(rect);
	CDC MemDC;			//首先定义一个内存显示设备对象
	CBitmap MemBitmap;		//定义一个位图对象
	//建立与屏幕显示兼容的内存显示设备
	MemDC.CreateCompatibleDC(NULL);
	//建立一个与屏幕显示兼容的位图
	MemBitmap.CreateCompatibleBitmap(pDC,rect.right,rect.bottom);
	//只有选入了位图的内存显示设备才有地方绘图,画到指定的位图上
	MemDC.SelectObject(&MemBitmap);
	MemDC.FillSolidRect(0,0,rect.right,rect.bottom,RGB(255,255,255));
	//绘图,添加你要的画图的代码,不过用MemDC画,而不是用pDC 
	
	/*...................*/ 
	
	//将内存中的图拷贝到屏幕上进行显示
	pDC->BitBlt(0,0,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY);
	//绘图完成后的清理 
	MemBitmap.DeleteObject();
	MemDC.DeleteDC();

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值