Title: An interesting special effect in one form
Question: How I can make one form to tremble, as occurs in the MSN Messenger when somebody asks for attention?
Answer:
For who it likes to place effect special (and useless) in form, this from there is an excellent tip:
declare in uses clausule of unit, the WINDOWS.PAS
procedure WindowShake(wHandle: THandle);
const
MAXDELTA = 4;
SHAKETIMES = 500;
var
oRect, wRect :TRect;
deltax : integer;
deltay : integer;
cnt : integer;
dx, dy : integer;
begin
//remember original position
GetWindowRect(wHandle,wRect) ;
oRect := wRect;
Randomize;
for cnt := 0 to SHAKETIMES do
begin
deltax := Round(Random(MAXDELTA)) ;
deltay := Round(Random(MAXDELTA)) ;
dx := Round(1 + Random(2)) ;
if dx = 2 then dx := -1;
dy := Round(1 + Random(2)) ;
if dy = 2 then dy := -1;
OffsetRect(wRect,dx * deltax, dy * deltay) ;
MoveWindow(wHandle, wRect.Left,wRect.Top,wRect.Right -
wRect.Left,wRect.Bottom - wRect.Top,true) ;
end;
//return to start position
MoveWindow(wHandle, oRect.Left,oRect.Top,oRect.Right -
oRect.Left,oRect.Bottom - oRect.Top,true) ;
end;
Usage:
procedure TForm1.Button1Click(Sender: TObject);
begin
WindowShake(Application.MainForm.Handle)
end;