2007年1月31日星期三

关于内存DC绘图防止屏幕闪烁说明

<a href=http://www.vczx.com/article/show.php?id=541>参考</a>
利用内存DC,进行绘图,从而减少闪烁,方法原理为:
此方法涉及到两个DC,屏幕DC和内存DC。把所要绘制的一切现在内存DC中进行绘制,之后全部搬到
屏幕DC中,从而把所有烦琐的绘制过程都在内存DC中完成了,用户在屏幕上看到的是一幅完整的图画,所以不可能出现
闪烁情况。期间,关键是这幅图画。这幅图画是从屏幕DC中创建出来的,只不画面的尺寸就是客户区域的大小,之后把
这幅画选入内存DC中,之后在内存DC中绘制的动作都在这幅画中,最后把内存DC中的这幅已经绘制好的画
在选入到屏幕DC中,达到最终目的。
方法:
首先创建关于屏幕的内存DC,MemDC.CreateCompatibleDC( pDC);
之后创建一幅关于屏幕DC的图画
CRect rect;
this->GetClientRect(rect);
CBitmap bmpFace;
bmpFace.CreateCompatibleBitmap(pDC,rect.Width(),rect.Height());注意把握rect的尺寸为客户区域大小;
之后将这幅画选入内存DC中,


CBitmap* pOldBmp = NULL;
pOldBmp = MemDC.SelectObject (&bmpFace);;
之后可以开始在内存DC中进行任何绘制动作;
CBrush brush(RGB(255,255,255));
MemDC.FillRect(rect,&brush);
for(int i=0;i<500;i++)
{
MemDC.MoveTo(22+i,22);
MemDC.LineTo(22+i,277);
}
绘制完后将内存DC中的这幅图绘制到屏幕DC中来,
pDC->BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&MemDC,rect.left,rect.top,SRCCOPY);
最后进行相关的资源回收动作,
MemDC.SelectObject(pOldBmp);
bmpFace.DeleteObject();。
同时我们要把系统的ON_WM_ERASEBKGND消息进行修改,否则也回出现狂闪情况。
return FALSE;

4 条评论:

匿名 说...

I am regular visitor, how are you everybody? This article posted at this web
page is really pleasant.

Also visit my blog post ... buy capsiplex cheap online

匿名 说...

Hello i am kavin, its my first occasion to commenting anyplace,
when i read this paragraph i thought i could also create comment due to this brilliant article.



my homepage; buy virility ex

匿名 说...

That is very interesting, You are a very professional blogger.
I have joined your rss feed and look forward to in quest
of more of your wonderful post. Also, I've shared your site in my social networks

Here is my page - breast actives for men

匿名 说...

Link exchange is nothing else but it is only placing the other
person's webpage link on your page at proper place and other person will also do same for you.

Feel free to visit my web page; mens Sexual health