Problems redrawing after minimize/restore
-
I have a dialog-based application, and I use a portion of the dialog for drawing some graphics. I have a problem when I minimize and then restore the dialog... I handle WM_SIZE (wParam == SIZE_RESTORED) to redraw my graphics, but this doesn't work because WM_PAINT occurs afterwards and redraws the entire dialog, leaving my graphics area blank. I tried moving my update function to WM_PAINT, but even that doesn't work, because the system redraws the dialog after my handler returns!! How is this problem typically solved?? For now, I'm going to start a 50msec timer in WM_SIZE, and redraw my graphics in that, then stop the timer. I've used this trick before, and it works well enough, but I know that's not how this is supposed to be done!!
-
I have a dialog-based application, and I use a portion of the dialog for drawing some graphics. I have a problem when I minimize and then restore the dialog... I handle WM_SIZE (wParam == SIZE_RESTORED) to redraw my graphics, but this doesn't work because WM_PAINT occurs afterwards and redraws the entire dialog, leaving my graphics area blank. I tried moving my update function to WM_PAINT, but even that doesn't work, because the system redraws the dialog after my handler returns!! How is this problem typically solved?? For now, I'm going to start a 50msec timer in WM_SIZE, and redraw my graphics in that, then stop the timer. I've used this trick before, and it works well enough, but I know that's not how this is supposed to be done!!
Within your
WM_PAINT
handler, call the default handler first to let the system draw the dialog. Then call your own routine to draw the graphics. Note that your handler must return zero to indicate that the message has been processed. You may also draw your graphics by handling theWM_ERASEBKGND
message using the same method (call default handler first and return zero EDIT: nonzero here). -
Within your
WM_PAINT
handler, call the default handler first to let the system draw the dialog. Then call your own routine to draw the graphics. Note that your handler must return zero to indicate that the message has been processed. You may also draw your graphics by handling theWM_ERASEBKGND
message using the same method (call default handler first and return zero EDIT: nonzero here).How do I call the default handler?? Do I do the same as with a subclassed control: return CallWindowProc (lpfnEditWndProc, hWndEdit, msg, wParam, lParam); At this point, this is not a subclassed function.
-
How do I call the default handler?? Do I do the same as with a subclassed control: return CallWindowProc (lpfnEditWndProc, hWndEdit, msg, wParam, lParam); At this point, this is not a subclassed function.
To call the default handler, call
DefWindowProc()
when using the Windows API. When using MFC, overrideOnPaint()
orOnEraseBkgnd()
and call the base class function first (e.g.CDialog::OnEraseBkgnd()
). Note that there is an error in my previous post (I will edit it):WM_ERASEBKGND
handlers must return nonzero when the background has been erased. You may also just get the return value of the default function and return that.