I'm having an annoying problem in a win32/d3d10 application. I'm using D3D to render a texture to the window, which worked fine as long as I kept constantly rendering, however I chose to render only when receiving WM_PAINT messages. Now when I start the application, the rendered texture is briefly shown but disappears the next instant, leaving a blank window. At first I thought there was something wrong with the rendering code, but user generated InvalidateRect calls (e.g. on mouse click/move etc.) get the texture rendered properly. Unfortunately, as soon as the window loses focus it becomes blank again.
I'm desperate, as after hours of research and debugging, I'm not really sure what is causing this. I suspect that it may have something to do with the validation of the window's update region, since
1.) ValidateRect won't actually validate the region (GetUpdateRect returns the same rectangle before and after ValidateRect)
2.) If I don't call either Begin-/EndPaint or DefWindowProc on WM_PAINT, the rendering works fine, however I keep getting WM_PAINT messages about once every second, because the update region doesn't get validated.
Although I wonder why ValidateRect doesn't work (as I'd like to avoid Begin-/EndPaint), when it seems to work for everyone else, I'm not sure it's actually the cause of my problem. It's probably some trivial issue, but I'm clueless and hoping that anyone else has encountered and solved it. Any hints are greatly appreciated.
[..]
case WM_ERASEBKGND:
return 1;
case WM_PAINT:
render();
break;
[..]
return DefWindowProc( hWnd, uMsg, wParam, lParam );
That's how the WM_PAINT and WM_ERASEBKGND messages get handled. The render() method would probably be more confusing than helpful and seems to work anyway.