|
#1
|
|||
|
|||
Хранитель экрана
Доброго всем дня, прогеры) В коде, который я привел ниже не увеличивается значение переменной kolvo(стоит на нуле) и я вообще не понимаю почему( Буду рад, если поможете разобраться, заранее всем спасибо)
Код:
unit Scrn; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, UnitList; type TScrnFrm = class(TForm) tmrTick: TTimer; procedure tmrTickTimer(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormHide(Sender: TObject); procedure FormActivate(Sender: TObject); private { Private declarations } procedure DrawVolna(x, y, size: integer; color: TColor); procedure DeactivateScrnSaver(var Msg: TMsg; var Handled: boolean); public { Public declarations } end; var ScrnFrm: TScrnFrm; i:cardinal; implementation {$R *.DFM} uses Cfg; var crs: TPoint; {Îðèãèíàëüíàÿ ïîçèöèÿ êóðñîðà ìûøè.} kolvo: Cardinal; function Min(a, b: integer): integer; begin if b < a then Result := b else Result := a; end; {Min} procedure TScrnFrm.DrawVolna(x, y, size: integer; color: TColor); var i, radius: cardinal; //cx, cy: integer; //xy1, xy2: integer; //r, g, b: byte; begin with Canvas do begin {Ïàðàìåòðû êàðàíäàøà è êèñòè.} Pen.Style := psClear; Brush.Style := bsSolid; Brush.Color := color; {Ðèñóþ êðóãè.} radius := size div 16; {for i := 0 to 2 do begin xy1 := (2 * dw) div 2; xy2 := size - xy1; Brush.Color := RGB(0, Min(g + (i * 8), 255), Min(b + (i * 8), 255)); Ellipse(x + xy1, y + xy1, x + xy2, y + xy2); end; } end; end; {TScrnFrm.DrawVolna} procedure TScrnFrm.DeactivateScrnSaver(var Msg: TMsg; var Handled: boolean); var done: boolean; begin if Msg.message = WM_MOUSEMOVE then done := (Abs(LOWORD(Msg.lParam) - crs.x) > 5) or (Abs(HIWORD(Msg.lParam) - crs.y) > 5) else done := (Msg.message = WM_KEYDOWN) or (Msg.message = WM_KEYUP) or (Msg.message = WM_SYSKEYDOWN) or (Msg.message = WM_SYSKEYUP) or (Msg.message = WM_ACTIVATE) or (Msg.message = WM_NCACTIVATE) or (Msg.message = WM_ACTIVATEAPP) or (Msg.message = WM_LBUTTONDOWN) or (Msg.message = WM_RBUTTONDOWN) or (Msg.message = WM_MBUTTONDOWN); if done then Close; end; {TScrnFrm.DeactivateScrnSaver} function GetItem (x, y:cardinal): TItem; begin result.scr.x:= x; result.scr.y:= y; result.scr.razmer:=15; //result.scr.max_razmer:= size div 5; end; procedure TScrnFrm.tmrTickTimer(Sender: TObject); var x, y: integer; size: integer; r, g, b: byte; color: TColor; begin {if sphcount >= CfgFrm.spnVolna.Value then begin Refresh; //sphcount:=0; end;} x := Random(ClientWidth); y := Random(ClientHeight); size := CfgFrm.spnSize.Value; x := x - size mod 2; y := y - size mod 2; r := Random($80); g := Random($80); b := Random($80); if not IsEmpty(list) then begin //ShowMessage('Ñïèñîê íå ïóñò!'); while List<>nil do // ïåðåáèðàåì âñå ýëåìåíòû ñïèñêà begin if (list.item.scr.razmer=5) then begin list.item.scr.x:= x; list.item.scr.y:= y; list.item.scr.razmer:=15; //ShowMessage('Ýëåìåíò îáíîâèëñÿ'); //list.item.scr.max_razmer:= size div 5; end else begin list.item.scr.razmer:=list.item.scr.razmer-1; //ShowMessage('Ðàçìåð óìåíüøåí'); end; List:=List^.Next; // ïåðåõîä ê ñëäóþùåìó ýëåìåíòó ñïèñêà end; end; ShowMessage(inttostr(kolvo)); //ShowMessage(inttostr(CfgFrm.spnVolna.Value)); if IsEmpty(list) or (kolvo < CfgFrm.spnVolna.Value) then //Åñëè ñïèñîê ïóñò èëè êîë-âî êàïåëü íà ýêðàíå ìåíüøå, ÷åì ìàêñèìàëüíî âîçìîæíîå ÷èñëî êàïåëü begin kolvo:=kolvo+1; //ShowMessage(inttostr(kolvo)); AddToFirst (list, GetItem(x, y)); //ShowMessage('Äîáàâëåí íîâûé ýëåìåíò'); end; DrawVolna(x, y, size, RGB(r, g, b)); end; {TScrnFrm.tmrTickTimer} procedure TScrnFrm.FormShow(Sender: TObject); begin //kolvo:=0; i:=0; GetCursorPos(crs); tmrTick.Interval := 1000 - CfgFrm.spnSpeed.Value * 90; tmrTick.Enabled := true; Application.OnMessage := DeactivateScrnSaver; ShowCursor(false); end; {TScrnFrm.FormShow} procedure TScrnFrm.FormHide(Sender: TObject); begin Application.OnMessage := nil; tmrTick.Enabled := false; ShowCursor(true); end; {TScrnFrm.FormHide} procedure TScrnFrm.FormActivate(Sender: TObject); begin WindowState := wsMaximized; end; {TScrnFrm.FormActivate} end. |