CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004
    Location
    Baltimore, MD
    Posts
    76

    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.

  2. #2
    Join Date
    Jan 2004
    Posts
    56
    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
  •  





Click Here to Expand Forum to Full Width

Featured