Lindawb 0 Posted February 28, 2022 Hello, I'm playing around to have small program with timer to change cursor with square, works but keeps old squares behind till I press F5. this was part of screen saver, but now trying to make it for kids play with it. procedure TForm1.Timer3Timer(Sender: TObject); var dc: HDC; canvas : TCanvas; P: TPoint; begin Windows.GetCursorPos(P); dc := GetWindowDC(0); canvas := Tcanvas.Create; try Canvas.Lock; Canvas.Handle := dc; Canvas.Pen.Width:=1; Canvas.Pen.Color := clYellow; Canvas.Brush.Color := clRed; Canvas.FillRect(Rect(p.X, p.Y,p.X+50,p.Y+50)); Canvas.Refresh; Canvas.UnLock; ReleaseDC(Handle, DC); finally ShowWindow(dc,SW_RESTORE); FreeAndNil(canvas); end; end; All I need is just keep the square where the mouse stops and clear previous canvas. if not possible, is there a way to load mouse cursor with small picture for kids ? I mean when kid moves the mouse shows animal image or any image. ! Thank you Share this post Link to post
Pat Foley 52 Posted February 28, 2022 How about low code drap n drop using Delphi IDE and VCL. Drop timage on the form Set the following form properties under F11 Key Color = clMoneyGreen TransparentColor = True TransparentColorValue = clMoneyGreen procedure TForm10.Timer1Timer(Sender: TObject); begin Image1.left := ScreenToClient(Mouse.CursorPos).X - Image1.width div 2; Image1.Top := ScreenToClient(Mouse.CursorPos).Y - Image1.Height div 2; end; Share this post Link to post
Lindawb 0 Posted February 28, 2022 Thank you, No that is not what I meant, if you see the code, the mouse outside the program,. in fact the program not visible. just desktop with slider. see attached image, what I want is to clear 1,2,3,4 boxes and keep last box. right now works, but keeps old boxes behind. Thank you Share this post Link to post
Pat Foley 52 Posted February 28, 2022 Just put the image you are using for the desktop into your program. double click on the form in the IDE to bring up FormCreate. set backgroundImage named imgAnimals with pix used for desktop image. You can use Panels for rendering your Boxes that have labels allready centered! imgAnimals := Timage.Create(Self) parent := Self; imgAnimals.align := alClient; imgAnimals.Picture.LoadFromFile(cAnimalPixPathed); (**above put this stuff. const cAnimalPixPathed = 'path and filename'; var imganimals: TImage; //Put upstairs BoxLabels := TList<TPanel> **); {You move the panels in BoxLabels around with mouse then use show and hide as necessary.} Share this post Link to post
Guest Posted March 1, 2022 (edited) implementation {$R *.dfm} uses System.Math; const MyBoxPadding: Integer = 30; var MyBox : TRect; MyBackgroundBMP: TBitmap; MyBitmpCursor : TBitmap; MyTextBox : string = 'Catch me'; procedure TViewFormMain.FormCreate(Sender: TObject); begin MyBackgroundBMP := TBitmap.Create; MyBitmpCursor := TBitmap.Create; // MyBackgroundBMP.LoadFromFile('..\..\background_children_playing.bmp'); MyBitmpCursor.LoadFromFile('..\..\MyButterFly.bmp'); // // Canvas.Draw(0, 0, MyBackgroundBMP); // Canvas.StretchDraw(TRect.Create(0, 0, Self.ClientWidth, Self.ClientHeight), MyBackgroundBMP); // // avoid call it all time... // Canvas.Pen.Width := 1; // Canvas.Pen.Color := clBlue; // Canvas.Brush.Style := bsClear; Canvas.Brush.Color := clBackground; // Canvas.Font.Color := clYellow; // text // Canvas.Brush.Bitmap := MyBitmpCursor; // // fullscreen // Self.BorderStyle := bsNone; // Self.WindowState := wsMaximized; // Timer1.Enabled := false; Timer1.Interval := 1000; Timer1.Enabled := true; end; procedure TViewFormMain.FormDestroy(Sender: TObject); begin MyBitmpCursor.Free; MyBackgroundBMP.Free; end; procedure TViewFormMain.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin // MyBox := TRect.Create(X - MyBoxPadding, Y - MyBoxPadding, X + MyBoxPadding, Y + MyBoxPadding); // // invalidate; // on Form to update all UI // if MyBox.Contains(TPoint.Create(X, Y)) then begin Timer1.Enabled := false; // ShowMessage('Yahoooooo... I won!'); // Timer1.Enabled := true; end; end; procedure TViewFormMain.FormPaint(Sender: TObject); begin // Canvas.Draw(0, 0, MyBackgroundBMP); Canvas.StretchDraw(TRect.Create(0, 0, Self.ClientWidth, Self.ClientHeight), MyBackgroundBMP); // // Canvas.FillRect(MyBox); Canvas.RoundRect(MyBox, 5, 5); Canvas.TextRect(MyBox, MyTextBox, [tfVerticalCenter]); end; procedure TViewFormMain.FormResize(Sender: TObject); begin invalidate; end; procedure TViewFormMain.Timer1Timer(Sender: TObject); var X, Y: Integer; begin X := RandomRange(0, Self.ClientWidth); Y := RandomRange(0, Self.ClientHeight); // MyBox := TRect.Create(X - MyBoxPadding, Y - MyBoxPadding, X + MyBoxPadding, Y + MyBoxPadding); // invalidate; end; initialization ReportMemoryLeaksOnShutdown := true; finalization end. Edited March 1, 2022 by Guest Share this post Link to post
Guest Posted March 1, 2022 (edited) using FireMonkey would more easy and rich to create "picknick" for children with lots of goodies mmmmm mmmm Edited March 1, 2022 by Guest Share this post Link to post