C++/Flicker in an MFC-based program
Hi Eddie - thanks for the message.
I do call Invalidate then UpdateWindow to force a repaint and the parameters (I'm reasonable sure) check out fine. One person has suggested using directdraw to allow the blt operation to be synched with the vertical blank pulse - all of which sounds a little scary to say the least! Can you or anyone help out here? there's a function - WaitForVerticalBlank which can be used with a DirectDraw object - could it be a simple matter of calling that, then calling my usual blt function once or would I need to fully implement the function directdraw style? If so how do I go about this?
Any help would again be much appreciated!
Just to remind you I'm trying to display two monochrome images alternately, but what I'm seeing is one image merging with the other over 5000 or so frames and then vice versa - could it be anything other than flicker?
thanks very much
I'm using VC++.NET (though the program was started on VC++6) and have a major problem with what I think is flicker. I am trying to display two alternating monochrome images, using an off-screen memory DC to buffer the images (with bitmaps made from uchar arrays) and BitBlt to display them on the screen as fast as possible (ideally showing one image per frame). I have tried various methods to get rid of the flicker, including overriding OnEraseBkgnd to just return TRUE, but I still get the flicker.
It is crucial that the flicker is removed as I'm using the screen as the input to an optical processing system. Any help/suggestions would be much appreciated!
Three things come to mind that could be the cause. Are you BitBliting in the OnPaint function from a class derived off of CWND? Are the paramaters being passed correctly with SRCCOPY and all that? Are you calling Invalidate anwhere to manually refresh when necessary? Have you tried using StrechBlt instead? Well, I think that was more than three things, but I hope they help you solve your problem. If none of those work just drop me another question.
Unless this is a huge project, I would highly suggest not getting involved with DirectX unless you know it already. Its an extremely confusing API. If the images are flickering, I was wondering if a hack like the following might fix it, assuming you want to change images every 5 seconds and that you're using BitBlt with a memory DC and a rendering DC:
// in WinMain
static DWORD time = GetTickCount();
while(GetTickCount() - time <= 5000)
// render first image
while(GetTickCount() - time <= 10000)
// render second image
time = GetTickCount();
That should do the trick to keep it from rendering any image more than once in the allotted time.
I hope this information was helpful.