Link to home
Start Free TrialLog in
Avatar of TimDSmith
TimDSmith

asked on

Hiding and showing the system mouse pointer

Hello Experts!

I'm trying to write an application that will hide the mouse cursor if it is idle (for more than, say, a second), and is shown when the mouse is moved.

I can set the system pointer, I just don't know how to get notification of when it's moving.
The application needs to show and hide the mouse even when using other applications.

There is an application that does this
http://www.softexe.com/cursorhider.html
but we can't afford licenses for every machine it will be installed on.

So I'm trying to do something similar.

I will also award points to anyone who can find a free application that does this.

Just to let you know the reason for this:
The systems will not have a keyboard and mouse, but Windows 98 (which we're using) insists on displaying the mouse cursor even if there is not a mouse attached.

Ok, I'll also award points for anyone who knows how to stop the mouse being displayed if there's not one attached :)
Avatar of Nass89
Nass89
Flag of United States of America image

Hi,
To hide mouse pointer, you may move it to right-bottom of screen. The following code hides and shows the mouse pointer:
   
      //m_pL is a Global or class member variable to save the last position of mouse  opointer
                POINT m_pL;

Hide_Pointer()
{
      GetCursorPos(&m_pL);
      SetCursorPos( 5000, 5000);
}

Show_Pointer()
{
      SetCursorPos(m_pL.x, m_pL.y);

}

Instead of detecting mouse attachment, write an Application to hide mouse cursor and run it at startup.

Good Luck!
Avatar of wayside
wayside

The CursorHider program you referenced registers a hook (SetWindowsHookEx) .

I'm guessing it uses a mouse hook (WH_MOUSE) to turn the cursor back on (probably with ShowCursor() ) whenever it detects a mouse event (mouse moved or button click or whatever, and probably uses a timer to turn it off if it hasn't moved in a second or two.

See the MSDN pages for SetWindowsHookEx ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp ) and MouseProc (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Hooks/HookReference/HookFunctions/MouseProc.asp ).
Please clear following things

1) You want to make mouse disappear only from your application or whole system
2)  what type of application you lhave ? (i.e. Dialog -modal modless,doc view -SDI MDI or console application dll etc..)

I have tested one solution in moda/modeless dialog and it is working fine

TAKE NEW CURSOR AND DO NOT DRAW ANYTHING
OVERRIDE ONMOUSEMOVE AND ONSETCURSOR AND ONTIMER HANDLER FUNCTION
ON TIMER SET MOUSE (WHICH HAS NO DRAWING)
ON MOUSE MOVE SET CURRENT MOUSE TO ARROW
ON SET CURSOR
  SET CURRENT CURSOR CALLING SetCursor() function



Avatar of TimDSmith

ASKER

I decided to write my own from scratch.

Download it from:

http://www.ezblitz.com/TimsHideCursor/TimsHideCursor.exe

The application runs in the system tray.

Left click the arrow icon to disable/enable cursor hiding.
Right click and select Exit from the menu to close.

I only hide the normal cursor at present as that's all I need to do, but I'll update it as and when required.

Hope people can find a use for this as well as me.

Thanks for your comments.

Kind regards

Tim

So, how did you wind up doing it?
I think you have enough clue now

;-)
I used a timer which fires every second. In the handler I call
GetCursorPos(&pos)
and compare it with the previous position. If it changes I show the mouse

HCURSOR cursor = app->LoadCursor(IDC_POINTER);
SetSystemCursor(cursor, 32512);

else I hide it and use a transparent icon.

I didn't bother using the hooks method, although this would have shown the mouse quicker when it began to move again.

Not sure who should get the points.
Perhaps me :)
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am looking for this kind of software too. Can U send the link again? The old domain is not working anymore.
Thanks.