Why does PrintWindow hate CS_PARENTDC? redux

Raymond Chen

Why does Print­Window hate CS_PARENT­DC? Because everybody hates CS_PARENT­DC! Commenter kero claims that it’s “easy to fix” the problem with Print­Window and CS_PARENT­DC. You just remove the CS_PARENT­DC style temporarily, then do the normal Print­Window, then restore the CS_PARENT­DC style. The question is then why Print­Window simply doesn’t do this. The question assumes that the described workaround actually works. It may work in limited situations, but it certainly doesn’t work in general. Since the CS_PARENT­DC style is a class style, removing the style affects all windows of that class, not merely the window you are trying to print. Suppose there are two windows of the class running on different threads, and you remove the CS_PARENT­DC style in anticipation of doing a Print­Window. While that’s going on, the other window gets a WM_PAINT message. Since the CS_PARENT­DC style was temporarily removed, that window will be painting with an incorrectly-clipped DC. Result: Incorrect pixels on the screen.

The proposed workaround doesn’t actually work reliably, which means that it probably shouldn’t be done at all. (Random reinforcement breeds superstition.)


Discussion is closed.

Feedback usabilla icon