I have found the following code to be an excellent solution which 
completely avoids the problems of LockWindowUpdate:


To: Craig Stuntz <[EMAIL PROTECTED]>
From: "Mike Orriss (TeamB)" <[EMAIL PROTECTED]>
Subject: Re: Help! LockWindowUpdate function
Date: Wed, 22 Mar 2000 18:47:01 GMT
Groups: borland.public.delphi.objectpascal

In article <[EMAIL PROTECTED]>, Craig Stuntz
wrote:
 > I'm not nitpicking -- these are important changes.
 >

I go further and now avoid LockWindowUpdate like the plague. It is far too
resource intensive and can cause flickering if your app doesn't cover the
whole desktop.

Instead I use the following routine:

   procedure LockControl(c: TWinControl; lock: boolean);
   begin
     if (c=nil) or (c.Handle=0) then exit;

     if lock then SendMessage(c.Handle,WM_SETREDRAW,0,0)
     else begin
       SendMessage(c.Handle,WM_SETREDRAW,1,0);
       RedrawWindow(c.Handle,nil,0,
           RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);
     end;
   end;


Example use (which prevents the dancing vertical scrollbar when
loading/expanding):

   LockControl(TreeView.Parent,True);
   try
     // modify the tree
   finally
     LockControl(TreeView.Parent,False);
   end;


  Mike Orriss (TeamB)
  (Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
  (Unsolicited e-mail replies will most likely be ignored)


At 13:56 21/05/2001 +1200, you wrote:
>  -----Original Message-----
>From: Robert Martin [mailto:[EMAIL PROTECTED]]
>Sent: Monday, May 21, 2001 12:26 PM
>To: Multiple recipients of list delphi
>Subject: [DUG]: Refreshing forms
>I am adding a largish number of components to a form.  Is there a way to 
>disable refreshing of the form until all components have been placed.  Is 
>there a method similar to the following for forms??
>
>....BeginUpdate
>try
>   ....
>   ....
>finally
>   ...EndUpdate
>end;
>
>
>Rob
>Software engineer
>Wild Software Ltd
><mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED]

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"

Reply via email to