场景:
1. 4种情况.
一般 闪烁是因为多次update ui,造成视觉上不连续的现象。
方法1:
This tiny class prevents redrawing of a wxWindow during its lifetime by using wxWindow::Freeze() and wxWindow::Thaw() methods. It is typically used for creating automatic objects to temporarily suppress window updates before a batch of operations is performed: void MyFrame::Foo() { m_text = new wxTextCtrl(this, ...); wxWindowUpdateLocker noUpdates(m_text); m_text-AppendText(); ... many other operations with m_text... m_text-WriteText(); } Using this class is easier and safer than calling wxWindow::Freeze() and wxWindow::Thaw() because you don't risk to forget calling the latter.
方法2:
wxWindow::Freeze() and wxWindow::Thaw();
2.2擦除窗口背景
6.正象我们前面提到的那样,另外一个减少闪烁的方法,是把背景和前景统一在窗口重画事
件处理函数中,而不是将它们分开处理,配合双缓冲
wxBufferedPaintDC,那么所有的绘画动作在完成之前都是在内存中进行的,这样在窗口被重
绘之前你将看不到窗口背景被更新.你需要增加一个空的背景擦除事件处理函数,并且使用S
etBackgroundStyle函数设置背景类型为wxBG_STYLE_CUSTOM以便告诉某些系统不要自动擦除
背景
3.重画事件是由于用户和窗口系统的交互造成的,但是它也可以通过调用wxWindow::Refres
h和wxWindow::
RefreshRect函数手动产生。果你准确的知道窗口的哪个部分需要重画,你可以指定只重画那
一部分区域以便尽可能的减少闪烁。
因为wxDialog关闭时,调用了顶级窗口的Refresh(),这个函数会连子窗口一起刷新.所以我们重载wxFrame的Refresh,空函数就没问题了。
void FrameBase::Refresh(bool eraseBackground, const wxRect * rect)
{
//do nothing.
//1.为了让wxDialog关闭时不闪烁.
}