Again, the only threadsafe way to draw on a window is to draw from the same thread that created a window; anything else is unsafe.
As a possible explanation why your code worked well with old Windows versions and does not work with modern versions read this The Old New Thing article.