Mega Code Archive

 
Categories / Delphi / System
 

How to eliminate flickering without using LockWindowUpdate(Handle)

Title: How to eliminate flickering without using LockWindowUpdate(Handle)? Question: How to eliminate flickering without using LockWindowUpdate(Handle)? Answer: I have an application in which the user drags TImage descendants around on a background image. When an image is dropped, I have to run through all the current images finding out where they are, and then arrange their z-order appropriately. When I do this, there's significant flickering. I've tried calling LockWindowUpdate(Handle) before the operation, then LockWindowUpdate(0) at the end, but several repaint operations still seem to take place at once. I'd like to be able to repaint the whole form once only, or failing that, limit the repaint to a specific area of the form (so that all my buttons etc, which aren't involved in any of this, don't have to flicker too). var FLockFormUpdatePile : integer; procedure TForm1.LockFormUpdate; begin if FLockFormUpdatePile = 0 then Perform(WM_SetRedraw, 0, 0); inc(FLockFormUpdatePile); end; procedure TForm1.UnlockFormUpdate; begin dec(FLockFormUpdatePile); if FLockFormUpdatePile = 0 then begin Perform(WM_SetRedraw, 1, 0); RedrawWindow(Handle, nil, 0, RDW_FRAME + RDW_INVALIDATE + RDW_ALLCHILDREN + RDW_NOINTERNALPAINT); end; end;