Problem with blitting dibSections

This is a discussion on Problem with blitting dibSections within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to use a dibSection to draw simple shapes, etc. on a window. It's kind of working, but it ...

Please note, that this is simply a contrived example to illustrate the error I'm experiencing - the actual code is rather large, so I'm sparing you the hassle.

If I call the square's draw method in the WM_CREATE handler, the subsequent blit () call in the WM_PAINT handler will cause the square to be drawn (naturally).

But if I wanted to make the square only draw itself when you click the mouse (as seen in the WM_LBUTTONDOWN handler), the square will not appear straight away - you have to cause a WM_PAINT event (like moving the window out of the screen and back).

The square's draw method calls the blit function itself but it has no effect! Only blit () calls from MainWindowProc seem to have any effect.

1. In WM_PAINT, BeginPaint/EndPaint should be used rather than GetDC.
2. Typically, all the painting to the target window is done in response to WM_PAINT. When you need to trigger a WM_PAINT you can call the InvalidateRect function.
3. Your blit function does not seem to take a target DC and the blit function is not posted so it is not clear how you are obtaining the target DC in the blit function. This may hold the reason that your painting from outside WM_PAINT is not working (although even if you get it working, as noted above, it may not be the best approach).

Hey thanks. I got it sorted the other day (when I stumbled upon that you could only paint from within the WM_PAINT message. I took your advice, though, and took the DC code from the WM_PAINT. The blit code gets the DC now, so that makes things neater, too.