MFC: flickering issue with GDI+
-
I create a sample dialog application which has a circle drawn. Also on mouse move the circle will be re-drawn. I am providing my code below. Its also compilable. I tried using double buffering and erasebackground, i was not getting the flickering issue, but i observed that the drawining is not erased properly. So to erase, in OnPaint i wrote the erasing code. Again i am facing the flickering issue. CPaintDC dc(this); GetClientRect(&clientRect); circle = clientRect; circle.DeflateRect(100,100); dc.SelectStockObject(NULL_BRUSH); dc.SelectStockObject(NULL_PEN); dc.FillSolidRect(circle, ::GetSysColor(COLOR_BTNFACE)); Bitmap buffer(circle.right, circle.bottom); Graphics graphicsbuf(&buffer); Graphics graphics(dc.m_hDC); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); SolidBrush brush(Color(255,71,71,71)); Pen bluePen(Color(255, 0, 0, 255),1); graphicsbuf.DrawEllipse(&bluePen,Rect(circle.left,circle.top,circle.Width(),circle.Height())); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); graphics.DrawImage(&buffer, 0, 0); } void CPOCDlg::OnMouseMove(UINT nFlags, CPoint point) { m_point = point; InvalidateRect(circle,FALSE); CDialogEx::OnMouseMove(nFlags, point); } BOOL CPOCDlg::OnEraseBkgnd(CDC* pDC) { return TRUE; } Please let me know if i am doing any mistake.
-
I create a sample dialog application which has a circle drawn. Also on mouse move the circle will be re-drawn. I am providing my code below. Its also compilable. I tried using double buffering and erasebackground, i was not getting the flickering issue, but i observed that the drawining is not erased properly. So to erase, in OnPaint i wrote the erasing code. Again i am facing the flickering issue. CPaintDC dc(this); GetClientRect(&clientRect); circle = clientRect; circle.DeflateRect(100,100); dc.SelectStockObject(NULL_BRUSH); dc.SelectStockObject(NULL_PEN); dc.FillSolidRect(circle, ::GetSysColor(COLOR_BTNFACE)); Bitmap buffer(circle.right, circle.bottom); Graphics graphicsbuf(&buffer); Graphics graphics(dc.m_hDC); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); SolidBrush brush(Color(255,71,71,71)); Pen bluePen(Color(255, 0, 0, 255),1); graphicsbuf.DrawEllipse(&bluePen,Rect(circle.left,circle.top,circle.Width(),circle.Height())); graphicsbuf.SetSmoothingMode(SmoothingModeHighQuality); graphics.DrawImage(&buffer, 0, 0); } void CPOCDlg::OnMouseMove(UINT nFlags, CPoint point) { m_point = point; InvalidateRect(circle,FALSE); CDialogEx::OnMouseMove(nFlags, point); } BOOL CPOCDlg::OnEraseBkgnd(CDC* pDC) { return TRUE; } Please let me know if i am doing any mistake.
I would imagine that since
OnMouseMove()
is called A BUNCH, your drawing code is not able to keep up. Just a guess, though."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
I would imagine that since
OnMouseMove()
is called A BUNCH, your drawing code is not able to keep up. Just a guess, though."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
That seems likely.
Steve