procedure TForm1.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)); //0~3的亂數值
deltay := Round(Random(MAXDELTA)); //0~3的亂數值
dx := Round(1 + Random(2)); //因為+1,所以亂數值為1~2
if dx = 2 then //將亂數值變為1 or -1
dx := -1;
dy := Round(1 + Random(2));//因為+1,所以亂數值為1~2
if dy = 2 then //將亂數值變為1 or -1
dy := -1;
OffsetRect(wRect,dx * deltax, dy * deltay); //偏移位置dx,dy決定正負方向,deltax決定偏移位置0~3
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;
procedure TForm1.Button1Click(Sender: TObject);
begin
WindowShake(Application.MainForm.Handle);
end;
星期四, 10月 04, 2007
讓你的視窗搖一下 (不像MSN震動,此為亂數搖)
新增一個TButton,並點兩下加入事件即可。
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言