Click to See Complete Forum and Search --> : Painting from a WM_PAINT Message


dro873
May 27th, 2004, 08:35 PM
My program animates some images on the screen. For normal animation I create an HDC called hdcMain using the GetDC method, and then make an HDC for back buffering called hdcBuffer by calling CreateCompatibleDC(hdcMain). I set a timer and for the WM_TIMER message, the program
calls a method and passes it the hdcBuffer device context. The method then paints onto the hdcBuffer. When the method returns, I then copy the hdcBuffer onto hdcMain. Now when painting from a WM_PAINT message, I use hdcMain = BeginPaint(hwnd,&paintStructObject) and then use hdcBuffer = CreateCompatibleDC(hdcMain) again, but when I try to pass hdcMain to my method, I get an unreferenced memory error. Can anyone tell me why my system works in normal animation but not from a WM_PAINT message.

sephiroth2m
May 28th, 2004, 06:23 AM
Your hdcMain is a common DC and there's no guarantee for its attributes between function calls. For your case I think u should use Private DC by specifying the CS_OWNDC window-class style.
Another way is declaring hdcBuffer as static or global variable, then call hdcBuffer= CreateCompatibleDC(hdcMain) once when initializing. In WM_TIMER, perfom painting onto the hdcBuffer, then in WM_PAINT, BitBlt it to hdcMain.