Recent

Author Topic: [SOLVED] How to change Windows cursor  (Read 637 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 641
[SOLVED] How to change Windows cursor
« on: December 19, 2025, 10:49:34 am »
Hello, how can I safely change the Windows cursor while the application is running and restore the default one?
« Last Edit: December 21, 2025, 09:30:27 am by Pe3s »

Zvoni

  • Hero Member
  • *****
  • Posts: 3260
Re: How to change Windows cursor
« Reply #1 on: December 19, 2025, 11:09:47 am »
Change as in System-Wide?

Don't!
Any program that changes anything in my System/OS goes straight into the rubbish bin....

If you want custom Cursors for your Program, use the Curser-Property of your Form(s), Controls, whatever.
User works with your Program, the cursor changes to your selected cursor, while when User opens Another Program in parallel it goes back to the standard cursor, as long as the user is "out of" your program
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Pe3s

  • Hero Member
  • *****
  • Posts: 641
Re: How to change Windows cursor
« Reply #2 on: December 19, 2025, 11:28:47 am »
I meant something like this: when picking a color from the screen, the cursor changes to a cross and returns to the system arrow after clicking.

Zvoni

  • Hero Member
  • *****
  • Posts: 3260
Re: How to change Windows cursor
« Reply #3 on: December 19, 2025, 11:33:03 am »
I meant something like this: when picking a color from the screen, the cursor changes to a cross and returns to the system arrow after clicking.
Cursor-Property of TScreen?
https://lazarus-ccr.sourceforge.io/docs/lcl/forms/tscreen.cursor.html
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Pe3s

  • Hero Member
  • *****
  • Posts: 641
Re: How to change Windows cursor
« Reply #4 on: December 19, 2025, 11:43:52 am »
I agree, but apart from the application, the cursor is standard.

Xenno

  • Jr. Member
  • **
  • Posts: 52
    • BS Programs
Re: How to change Windows cursor
« Reply #5 on: December 19, 2025, 01:23:23 pm »
In an app involving a mouse hook I've built years ago, I rely on code as below:

Code: Pascal  [Select][+][-]
  1. var
  2.   CurHnd: HCursor;
  3.  
  4.   // change
  5.   CurHnd := LoadCursor(0, IDC_CROSS); // IDC_....
  6.   SetSystemCursor(CurHnd, OCR_NORMAL);
  7.  
  8.   // restore
  9.   SystemParametersInfo(SPI_SETCURSORS, 0, Nil, 0);

While my app restores mouse cursor in a message handler (sent by the mouse hook dll), it could also be simplified in try-finally.
 
Code: Pascal  [Select][+][-]
  1.   // change
  2.   CurHnd := LoadCursor(0, IDC_CROSS); // IDC_....
  3.   SetSystemCursor(CurHnd, OCR_NORMAL);
  4.   try
  5.     // ..
  6.     // your code
  7.     // ..
  8.   finally
  9.     // restore
  10.     SystemParametersInfo(SPI_SETCURSORS, 0, Nil, 0);
  11.   end;

Cursor might use .cur file.
Lazarus 4.0, Windows 10, https://www.youtube.com/@bsprograms

Pe3s

  • Hero Member
  • *****
  • Posts: 641
Re: How to change Windows cursor
« Reply #6 on: December 21, 2025, 09:30:09 am »
Thank you  :)

 

TinyPortal © 2005-2018