-
May 27th, 2004, 07:35 PM
#1
Painting from a WM_PAINT Message
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.
-
May 28th, 2004, 05:23 AM
#2
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.
Trust urself!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|