Is this the correct solution? Have you tested this?
This sounds like this is for bug 51140. I suspect the right solution is (instead? additionally?) to not send WM_ERASEBKGND when a child is hidden; see my comments there. Of course that also needs tests, and it needs bug 6006 to be retested and/or re-debugged.