如何避免在MFC中闪烁 [英] How to avoid flickering in mfc

查看:97
本文介绍了如何避免在MFC中闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的SDI应用程序中有很多图纸.当我滚动窗口时,它会闪烁很多.任何人都可以给我一种简单的方法来处理滑动的问题.我为每个类都创建了对象(包含rect,ellipse等图纸) OnDraw.我绘制PolyLine的代码如下,

Calc_Line * objPline =新的Calc_Line();
objPline-> Place_Line(667-posX,155-posY,675-posX,155-posY,675-posX,185-posY,667-posX,185-posY);//函数调用
//被调用函数中的pDC.

这里PosX,PosY是滚动后滚动点的位置,(重新计算点),就像我绘制了所有图纸一样,需要您的协助才能停止闪烁.

在此先感谢,
Shiva ..

Hi all,

There are lot of drawings in my SDI application.when i scroll the window it flickers much.Can any one pls give me the easy way to handle the flickeing.I have created objects for each class(contains drawings such as rect,ellipse)in OnDraw.And my code to draw a PolyLine is as follows,

Calc_Line* objPline = new Calc_Line();
objPline->Place_Line(667-posX,155-posY,675-posX,155-posY,675-posX,185-posY,667-posX,185-posY);//Function Calling
//pDC in called function.

Here PosX,PosY are the positions of Scroll Point after scrolling,(Recalculating the points),Like this i have drawn all the drawings,Need ur assistance to stop flickering.

Thanking in advance,
Shiva..

推荐答案

这通常是因为在重新绘制内容之前首先擦除了背景.
如果您要进行所有擦除和绘制,则不需要此操作.

因此,处理WM_ERASEBKGND消息并返回非零值.
This usually happens because the background is first erased before the contents are redrawn.
This is not needed if you''re doing all the erasing and drawing yourself.

So handle the WM_ERASEBKGND message and return a nonzero value.


«_ Superman_»的答案为您提供了基本原理.删除背景(将其全部涂成白色)然后在其上进行绘制是处理显示的一种简单,通用,简单的方法.但是,它容易闪烁.按照相同的原理,在显示器上绘制实心矩形,然后绘制不同的颜色,重叠的矩形也是闪烁的来源.

现在,您如何实现«_Superman_»的建议并将其扩展到包括处理重叠的图形?一种解决此问题的方法称为双缓冲.如果您进行搜索,您将在CodeProject和其他Web站点上找到有关此内容的材料.我建议本文 [
«_Superman_»''s answer gives you the basic principle. Erasing the background (painting it all white) then drawing on top of it is the easy, common, simple approach to handling the display. However, it is susceptible to flicker. On the same principle, drawing a solid rectangle on the display and then a different color, overlapping rectangle is also a source of flicker.

Now, how do you implement «_Superman_»''s advice and extend it to include dealing with drawing overlapping stuff? One approach to deal with this is called double buffering. If you search, you will find material about this both on CodeProject and the rest of the web. I would suggest this article[^].

Doing this is more important than my other response''s suggestion of using ScrollWindow(). Once you do this, ScrollWindow() use is more a potential optimization than flicker reduction.

If your window contains child window controls, you might also want to look at the WS_CLIPCHILDREN windows style.


要完全消除闪烁,请不要使用OnEraseBackground陷阱,而不要调用基类和返回FALSE ...我认为这可能是TRUE,但您不应该调用基类...

之后,您应该使用Memory DC绘制...

这样可以消除闪烁!
To illiminate flickering completelly you shoud trap de OnEraseBackground and don''t call the based class and return FALSE... I think it is FALSE of maybe TRUE but you shouldnt call the base class...

After that you should use a Memory DC to draw...

This will elliminate flickering definitelly!!


这篇关于如何避免在MFC中闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆