[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

flickering

Posted on 2004-11-15
7
Medium Priority
?
776 Views
Last Modified: 2010-04-05
Hello,

In my application I have a form with a lot of TImages on it. Simultaneously changing their appearance in the rutime causes the window to unpleasantly flicker for a second or even more. How can I block it until all the procedures are over?

Vadim Smolensky,
Saint-Petersburg, Russia
0
Comment
Question by:VSmolensky
7 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 12588270
Hi,
Do You set DoubleBuffered property of frame to true?
0
 

Author Comment

by:VSmolensky
ID: 12588641
A frame? It's not a frame, it's a form. Or don't I understand anything?
0
 
LVL 17

Expert Comment

by:mokule
ID: 12588676
Sorry. Form, I mean form of course.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Expert Comment

by:Newt6398
ID: 12589014
Try this you may need to adapt it a bit to your needs.


{ This little demo shows how to make a selection rectangle to be
controlled with your
  mouse, without having to endure the pains of flicker.

  What we do in this scenario is consider two rectangles: one rectangle
  being larger than the other. We then paste the smaller rectangle over
  top of the larger rectangle matching them at x1, y1. Then, using XOR
  addition of bits, we subtract the difference in regions and construct a
  new region of difference between the two. This region is then inverted
  and pasted onto the screen.  

  Written by Greg Holowatinc for SK Computer Solutions WEB Page TIPS
  Section contact:  nwillams@telusplanet.net (MetZ on #Delphi on EFNET}

  Note: If testing this in Delphi, make sure that in object inspector, you
  set the                 OnMouseDown and OnMouseUp events to
  FormMouseDown. Also, set the OnMouseMove to
        FormMouseMove.  
}    

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
    RBeg, REnd: TRect;
    Capturing: Boolean;
  public
    procedure DrawDelta(Loc: HDC; RNew, ROld: TRect);
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


{ Capture the OnMouseDown event; we set up the first rectangle upon
  the mouse being clicked and set the capturing flag on. }

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if not Capturing then
  begin
    Capturing := True;
    RBeg.Top := Y;
    RBeg.Left := X;
    RBeg.Bottom := Y;
    RBeg.Right := X;
    REnd.Top  := Y;
    REnd.Left := X;
  end else
    Capturing := False;
end;


{ Capture the OnMouseMove event; we update the X2, Y2 of the big
rectangle, then call DrawDelta and make the small rectangle the
same as the big rectangle }

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if Capturing then
  begin
    REnd.Bottom := Y;
    REnd.Right := X;
    DrawDelta(Form1.Canvas.Handle, RBeg, REnd);
    RBeg.Bottom := Y;
    RBeg.Right := X;
  end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 Capturing := False;
end;

{ This is the main procedure for filling in the delta region }

procedure TForm1.DrawDelta(Loc: HDC; RNew, ROld: TRect);
var
  { Set some variables of Handle To Region HGRN }
  RegBig, RegSmall, RegNew: HRGN;
begin
  { Create all the regions out of the rectangles passed as
val. parameters }
 RegSmall := CreateRectRgn(ROld.Left, ROld.Top, ROld.Right, ROld.Bottom);
 RegBig := CreateRectRgn(RNew.Left, RNew.Top, RNew.Right, RNew.Bottom);
 RegNew := CreateRectRgn(0, 0, 0, 0);
{ Combine the two rectangles using GRN_XOR flag to check;
if both bits are present then used then the region does not
exist, hence the area that is already marked as inverted,
does not updated again. This is the way we  prevent flicker. }
  CombineRgn(RegNew, RegSmall, RegBig, RGN_XOR);
  { Invert then newly created region. }
  InvertRgn(Loc, RegNew);
  { Remove all the regions from memory }
  DeleteObject(RegBig);
  DeleteObject(RegSmall);
  DeleteObject(RegNew);
end;

end.
0
 
LVL 6

Accepted Solution

by:
Imthiyaz_ph earned 200 total points
ID: 12590540
Try using the LockWindowUpdate API to disable painting for a window.

LockWindowUpdate(
    HWND hWndLock       // handle of window to lock  
   );

Pass the handle of the form as parameter to LockWindowUpdate before changing the appearance. After the change is complete, use LockWindowUpdate(0) to unlock the window.
0
 

Author Comment

by:VSmolensky
ID: 12591835
LockWindowUpdate works perfectly.
DoubleBuffered:=True make the flickering even worse.
I accept the comment from Imthiyaz_ph. Thank you!
0
 

Expert Comment

by:mehdi_m
ID: 12745905
ok
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month19 days, 9 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question