I have a window and it has a WS_EX_COMPOSITED extended style, I handle the WM_ERASEBKGND Notification and wm_paint message, everything seems right, but when I call GetDC&ReleaseDC in some place, and do some drawing with GDI functions, I simply can't draw it on the window, during I debug the program, I found that after my drawing calls, the window will handle the wm_erasebkgnd and wm_paint messages, and the action in erasebkgnd overlap the drawing, and this is why the drawing seems doesn't work,
and after I remove the ws_ex_composited style, there is no more wm_paint message ,and GetDC could work,
now I just wonder if there is a ws_ex_composited style, then you can't drawing outside erasebkgnd handler and wm_paint handler, am I right?
Is there anyone who have meet the similar problem?
Re: GetDC and drawing problem with WS_EX_COMPOSITED
Drawing outside WM_PAINT and WM_ERASEBKGND will indeed not work right for a WS_EX_COMPOSITED style window.
The reason why should be obvious. Part of the composition consists of creating an off-screen image for the double buffer then iterate down to top through the windows to have each window in the area paint itself (accounting for (semi)transparancy) and having the double buffer blit in one go to the actual screen. This double buffering isn't active when you're just painting something "somewhere" in your code.
You can make it work (sort of), but as soon as you go on vista with desktop composition enabled it'll break down because now you're not actually painting to the window canvas but to the desktop directly. If you really really NEED to paint outside of those 2 functions, and need the features of composition your safest bet is making a single top level window and handling all composition yourself, but that means you can't use standard Window controls.