Recent

Author Topic: How to show or hide the mouse  (Read 11408 times)

witenite

  • New Member
  • *
  • Posts: 41
How to show or hide the mouse
« on: August 16, 2016, 11:09:27 am »
Hi,
I recently converted a program I have written using Delphi into Lazarus. My program has the following command in its code:

ShowCursor(False);  // Hide cursor (Mouse) when we hover anywhere over the form

This however cannot compile (Lazarus does not know what showcursor is). Basically this is a method for hiding the mouse whenever the mouse is over my form (I don't want to see the mouse cursor, and this works perfectly in Delphi). I have looked online for help, but the best I could find was a very old reference here:

http://forum.lazarus.freepascal.org/index.php?topic=11655.0

Apparently showcursor used to work many years ago, but no longer does (or at least that is the best interpretation I can get from the forums. Am I missing a USE file or link, or does Lazarus have some other means of hiding the cursor?

balazsszekely

  • Guest
Re: How to show or hide the mouse
« Reply #1 on: August 16, 2016, 11:22:48 am »
I suppose you're under windows. If yes, just add JwaWindows to the uses clauses and you're good to go.

Code: Pascal  [Select][+][-]
  1. uses JwaWindows;
  2.  
  3. procedure TForm1.FormMouseEnter(Sender: TObject);
  4. begin
  5.   ShowCursor(False);
  6. end;
  7.  
  8. procedure TForm1.FormMouseLeave(Sender: TObject);
  9. begin
  10.   ShowCursor(True);
  11. end;
  12.  

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: How to show or hide the mouse
« Reply #2 on: August 16, 2016, 11:39:41 am »
I suppose you're under windows. If yes, just add JwaWindows to the uses clauses and you're good to go.
Uh... doesn't the Windows-unit have the same ShowCursor() defined?  :D
(at least trunk does)

Code: Pascal  [Select][+][-]
  1. uses Windows;


balazsszekely

  • Guest
Re: How to show or hide the mouse
« Reply #3 on: August 16, 2016, 11:46:53 am »
Quote
@rvk
Uh... doesn't the Windows-unit have the same ShowCursor() defined?
Yes it does, but I like jwaWindows better, it's seem to me that it has a more complete api declarations.  :)

Zath

  • Sr. Member
  • ****
  • Posts: 391
Re: How to show or hide the mouse
« Reply #4 on: August 16, 2016, 02:31:57 pm »
Quote
@rvk
Uh... doesn't the Windows-unit have the same ShowCursor() defined?
Yes it does, but I like jwaWindows better, it's seem to me that it has a more complete api declarations.  :)
So does this mean there are duplicate options within the default Lazarus installation ?

balazsszekely

  • Guest
Re: How to show or hide the mouse
« Reply #5 on: August 16, 2016, 04:37:33 pm »
Quote
@Zath
So does this mean there are duplicate options within the default Lazarus installation ?
Although are some overlapping api declarations, I wouldn't call it "duplicate". The windows unit is similar to delphi's windows unit, jwaWindows on the other hand is the port of the JEDI API library & security code library.

RWC

  • Jr. Member
  • **
  • Posts: 92
Re: How to show or hide the mouse
« Reply #6 on: August 16, 2016, 04:58:26 pm »
How about: Form1.Cursor := crNone; //in LCL/controls.pp?
LAZARUS  : Lazarus-1.4.2-fpc-2.6.4-win32. OS   : Windows Vista 32bit Home Premium SP2.
CPU  : Intel Core2 Quad CPU Q6600 2.4GHz. RAM : 3GB. PCIE : NVIDIA GeForce GT610. Audo : NVIDIA HD Audio.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4468
  • I like bugs.
Re: How to show or hide the mouse
« Reply #7 on: August 16, 2016, 05:29:29 pm »
How about: Form1.Cursor := crNone; //in LCL/controls.pp?

Yes, that is the cross-platform solution.
Please remember that Lazarus is a cross-platform system and lots of effort was made to implement it.
The Windows unit or similar should not be used, unless you are really creating a Windows specific program!
« Last Edit: August 16, 2016, 05:31:14 pm by JuhaManninen »
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

balazsszekely

  • Guest
Re: How to show or hide the mouse
« Reply #8 on: August 16, 2016, 06:40:39 pm »
Ok, but the OP explicitly asked about ShowCursor api.

witenite

  • New Member
  • *
  • Posts: 41
Re: How to show or hide the mouse
« Reply #9 on: August 17, 2016, 11:49:21 am »
I suppose you're under windows. If yes, just add JwaWindows to the uses clauses and you're good to go.

Code: Pascal  [Select][+][-]
  1. uses JwaWindows;
  2.  
  3. procedure TForm1.FormMouseEnter(Sender: TObject);
  4. begin
  5.   ShowCursor(False);
  6. end;
  7.  
  8. procedure TForm1.FormMouseLeave(Sender: TObject);
  9. begin
  10.   ShowCursor(True);
  11. end;
  12.  

witenite

  • New Member
  • *
  • Posts: 41
Re: How to show or hide the mouse
« Reply #10 on: August 17, 2016, 11:51:45 am »
I suppose you're under windows. If yes, just add JwaWindows to the uses clauses and you're good to go.

Code: Pascal  [Select][+][-]
  1. uses JwaWindows;
  2.  
  3. procedure TForm1.FormMouseEnter(Sender: TObject);
  4. begin
  5.   ShowCursor(False);
  6. end;
  7.  
  8. procedure TForm1.FormMouseLeave(Sender: TObject);
  9. begin
  10.   ShowCursor(True);
  11. end;
  12.  
Actually I'm using Lazarus on my home computer, which is Linux (Ubuntu) based. The Delphi package I use at work though, which is Windows based, hence the reason for using Showcursor.

witenite

  • New Member
  • *
  • Posts: 41
Re: How to show or hide the mouse
« Reply #11 on: August 17, 2016, 11:54:14 am »
How about: Form1.Cursor := crNone; //in LCL/controls.pp?

Thanks! based on what I have read down below, this is a cross platform option, which will work quite nicely for me, as I am not using Windows at home, but instead run Ubuntu Linux. Thanks for all your help (and to the other people providing useful comments here too).

Sergei

  • New member
  • *
  • Posts: 8
Re: How to show or hide the mouse
« Reply #12 on: November 17, 2017, 02:16:49 pm »
Code: Pascal  [Select][+][-]
  1. Screen.Cursor := crNone

rvk

  • Hero Member
  • *****
  • Posts: 6163
Re: How to show or hide the mouse
« Reply #13 on: November 17, 2017, 02:22:50 pm »
Code: Pascal  [Select][+][-]
  1. Screen.Cursor := crNone
Note that Screen.Cursor := crNone doesn't completely eliminate the mouse-pointer.
When you hover over a border of an edit, the mouse-pointer is visible again (and invisible again if you move off the border).

ShowCursor(False) does not have that problem (but might be a Windows-only solution).

 

TinyPortal © 2005-2018