Board index » delphi » endless OnPaint events

endless OnPaint events

Is it possible to create endless OnPaint events
for example to change windows background continuously
without using a timer object ?
 

Re:endless OnPaint events


Hi !

2 suggestions:

a) A Thread running in the background with relatively high priority (tpNormal or above) and a short
delay (gives a steady painting, but freezes app for short moments), or with lower priority and no
delay. The latter will cause all free time to be used for painting, but repainting does not take
place (or rarely) if other activity in the app.

b) Refreshing in an Application.OnIdle event-handler ? This event is fired continously when nothing
else happens. of course, no painting when otherwise busy app.

--

Bjoerge

<<martin steig skrev i meldingen <378a48b6.46052...@news.siemens.at>...
Is it possible to create endless OnPaint events
for example to change windows background continuously
without using a timer object ?>>

Re:endless OnPaint events


Quote
"Bj?rge S?ther" wrote:

> b) Refreshing in an Application.OnIdle event-handler ? This event is fired continously when nothing
> else happens.

Not quite... it gets called when the application message queue is
emptied. It only gets called continuously if your code in that handler
directly or indirectly ends up posting another message to the message
queue.

MH.

--
Martin Harvey.
mar...@aziraphale.demon.co.uk
mc...@harvey27.demon.co.uk
http://www.harvey27.demon.co.uk/mch24/
EFFNet: Diaspar-
ICQ: 37298917

Jesus replied: "I am the way, the truth, and the life;
no one comes to the Father, except by me."
(John 14:6).

Re:endless OnPaint events


Quote
<<"Bj?rge S?ther" wrote:

> b) Refreshing in an Application.OnIdle event-handler ? This event is fired continously when
nothing
> else happens.

Not quite... it gets called when the application message queue is
emptied. It only gets called continuously if your code in that handler
directly or indirectly ends up posting another message to the message
queue.

Quote

Hi !

Check out this one:

-----------
unit UMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type

  TColorDir = (cdRed, cdBlue, cdGreen, cdYellow);

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    FColorDir: TColorDir;
    procedure AppIdle(Sender: TObject; var Done: Boolean);
  public
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnIdle:=AppIdle;
end;

procedure TForm1.AppIdle(Sender: TObject; var Done: Boolean);
var
  R, G, B: byte;
begin
  R:=Color and $FF;
  G:=(Color and $FF00) shr 8;
  B:=(Color and $FF0000) shr 16;
  case FColorDir of
    cdRed:  begin
              if R < $FF then inc(R);
              if G > 0 then dec(G);
              if B > 0 then dec(B);
              if (R = $FF) and (G or B = 0) then FColorDir:=cdBlue;
            end;
    cdBlue: begin
              if B < $FF then inc(B);
              if G > 0 then dec(G);
              if R > 0 then dec(R);
              if (B = $FF) and (R or G = 0) then FColorDir:=cdGreen;
            end;
    cdGreen:begin
              if G < $FF then inc(G);
              if B > 0 then dec(B);
              if R > 0 then dec(R);
              if (G = $FF) and (R or B = 0) then FColorDir:=cdYellow;
            end;
    cdYellow: begin
              if G < $FF then inc(G);
              if R < $FF then inc(R);
              if B > 0 then dec(B);
              if ((G = $FF) and (R = $FF)) and (B = 0) then FColorDir:=cdRed;
            end;

  end;
  Color:=R+(G shl 8)+(B shl 16);
end;

end.

---------

It causes a continously changing background color...

--

Bjoerge

Martin Harvey skrev i meldingen <378B7C7C.DB5A4...@aziraphale.demon.co.uk>...

Re:endless OnPaint events


Quote
"Bj?rge S?ther" wrote:

> It causes a continously changing background color...

Well of course it does you ninny!!! The changes result in more WM_PAINT
messages occurring!!!!!!!!

MH.

--
Martin Harvey.
mar...@aziraphale.demon.co.uk
mc...@harvey27.demon.co.uk
http://www.harvey27.demon.co.uk/mch24/
EFFNet: Diaspar-
ICQ: 37298917

Jesus replied: "I am the way, the truth, and the life;
no one comes to the Father, except by me."
(John 14:6).

Re:endless OnPaint events


This example works fine, but if the window
is moved or resized, no idle events are generated.
How can I get continuously events in this case ?

// idle handler example generates random colored background
// but moving or sizing the window interrupts the idle handling !
unit Idle;

interface  

uses windows, Forms;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    procedure IdleHandler(Sender: TObject; var Done: Boolean);
  end;

var  Form1: TForm1;

implementation

{$R *.DFM}

{add call to this methode at Form1 event OnCreate !}
procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnIdle := IdleHandler;
end;

procedure TForm1.IdleHandler(Sender: TObject; var Done: Boolean);
begin
  Color := random($FFFFFF);
end;

end.

Re:endless OnPaint events


<<Martin Harvey:

Quote
"Bj?rge S?ther" wrote:

> It causes a continously changing background color...

Well of course it does you ninny!!! The changes result in more WM_PAINT
messages occurring!!!!!!!!

Quote

..which I believe was the point...If I knew what "ninny" means, I would definately call you
something, too...just don't know if it's good or bad to be a ninny.

--

Bjoerge

Re:endless OnPaint events


Quote
"Bj?rge S?ther" wrote:

> ...which I believe was the point...If I knew what "ninny" means, I would definately call you
> something, too...just don't know if it's good or bad to be a ninny.

It's a fairly light hearted slur :-)

MH.

--
Martin Harvey.
mar...@aziraphale.demon.co.uk
mc...@harvey27.demon.co.uk
http://www.harvey27.demon.co.uk/mch24/
EFFNet: Diaspar-
ICQ: 37298917

Jesus replied: "I am the way, the truth, and the life;
no one comes to the Father, except by me."
(John 14:6).

Other Threads