| h4344 (43) | |||
So im trying to fix the flickering in my program because it updates very quickly, im still new with drawing so im not too sure what im doing wrong here.
| |||
|
Last edited on
|
|||
| andywestken (1964) | |
|
I can spot three things wrong with your code, assuming it's from your WM_PAINT handler. 1. You should use BeginPaint/EndPaint rather than GetDC/ReleaseDC 2. You're not selecting your bitmap into the memory DC 3. You're drawing on the windows DC rather than memory DC Also, when you use this approach you are responsible for painting the whole of the window. If you haven't done so already, you need provide a WM_ERASEBKGND handler which does nothing. Otherwise you'll still get flickering. And you'll need to paint the whole of the window (or invalidated region, if it's a partial update) And you're "red" rectangle looks black? Andy | |
|
Last edited on
|
|
| guestgulkan (2915) | |||
Also the sequence in which the pen handles are created and selected in and out of the device context looks dodgy and smells of resource mismanagement
| |||
|
|
|||
| h4344 (43) | |
|
@Andy I replaced DC with Beginpaint, im not too sure how to go about fixing the last 2 issues though (again im new at this). | |
|
|
|
| andywestken (1964) | |
|
2. Use SelectObject to select the bitmap into the memory dc, in the same way you select the pens, keeping the old one to swap back later (for consistency). 3. The other SelectObject calls (with the pens) should use hdcmem, as should the various drawing calls. That is, all the calls between // Start drawing and the BitBlt. BitBlt then blits the bitmap from the memory dc (dcmem) onto the window dc (dc). Note that the BitBlt line is fine except for the size. Remember to use SelectObject to restore the old bitmap before deleting the memory dc and bitmap. You also need to fix the problems guestgulkan mentioned. You need to delete all the pens you created, and restore the old pen (the one which was there at the beginning). Etc Andy | |
|
Last edited on
|
|
| EssGeEich (1007) | |||
From MSDN ( http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx )
Using WS_EX_COMPOSITED when creating your window (in the Extended Window Style) will fix the issue, MSDN said. | |||
|
Last edited on
|
|||