Hello Andrew,
I don't think this is the right fix. Based on my tests, and bug 51140 [1], I don't think we should be sending WM_ERASEBKGND even if the window does have WM_PARENT. E.g. the attached patch on top of your tests works on my Windows machine, but still fails on Wine.
When I tested it earlier I was unable to find a set of conditions where Windows does send WM_ERASEBKGND to the parent of a hidden window, but I didn't want to just remove that code without re-debugging bug 6006 [2].
ἔρρωσο, Zebediah