Hide mouse cursor


#1

Hey, I want to hide the mouse cursor when a user mouses over a Slider. What I did is basically this:

 #include <windows.h>

class MySlider: public Slider
{

public:
    MySlider( const String& componentName ) : Slider(componentName) {}
    ~MySlider() {}

    void mouseEnter( const MouseEvent& e )
    {
        SetCursor(0);
    };
};

This works fine in Windows 7 64 Bit with Live 8, with a 32bit VST plugin, but it does not hide the mouse cursor with Cubase 5. Calling SetCursor(0) in another 32bit VST plugin that does not use JUCE works fine, though.

Any ideas?


#2

slider->setMouseCursor (MouseCursor::NoCursor) ?


#3

Thanks for the fast reply! I tried this, too, and it hides the mouse cursor in Ableton Live 8, but it does not have any effect in Cubase 5.


#4

I don’t know then - the juce call I suggested will just call SetCursor(0) internally, and I’ve no idea what cubase could be doing to break it…


#5

What is confusing, though, is that it works in another plugin of mine that does not use JUCE, and just calls SetCursor(0).


#6

There must be some subtle window behaviour difference that cubase doesn’t like… Can’t think what it could be though. Does keyboard focus make a difference?


#7

I am not sure what to test with Keyboard focus? I tried setWantsKeyboardFocus(…) but this does not make a difference.

I just found out that hiding the mouse works in Cubase 5 if I do it in , but it does not work in or (I made sure that the code is executed in all cases).

So this hides the mouse (until I leave the Slider):

void mouseMove
( const MouseEvent& e )
{
    setMouseCursor (MouseCursor::NoCursor);
    updateMouseCursor();
};

#8

When I suggested calling slider->setMouseCursor (MouseCursor::NoCursor), you didn’t stick that in the mouseEnter callback, did you? Surely if you just call it on the slider as soon as it gets constructed, that’d work?


#9

Again thanks for your fast reply…

I tried different options. Calling it on the slider after it gets constructed does not work for Cubase 5, but does for Live 8. Also, putting it in the callback does not work for Cubase 5, but works for Live 8.


#10

Just setting the slider’s cursor to NoCursor means that it should take care of updating it whenever the cursor moves over it, you shouldn’t need to do anything special. What I don’t understand is why the mouseMove callback would do something but the mouseEnter wouldn’t… both are just generated internally from the same incoming OS events. Does the mouseEnter not get called when running in cubase?


#11

gets called.


#12

I bet what’s happening is that each time the mouse moves, cubase updates the cursor to its own one.

So if you use mouseMove to force the cursor to update every time, and if you’re lucky enough to receive the mouse move event after cubase, then it’s your cursor you’ll see. Normally, the juce code only bothers forcing a cursor update when it actually changes, so I bet you’ll see a brief flash of it disappearing as you move into the slider, and then cubase will come along and force put own cursor again at the next mouse move.


#13

It turns out that I need to hide the cursor via Windows API as well if I want it to disappear immediately on click. As an example, this is custom code for having a customized Slider that hides the mouse on MouseDown and displays it again on MouseUp:

#include <windows.h>

class MySlider: public Slider
{

public:
    MySlider
    ( const String& componentName )
    : Slider(componentName)
    {
    }

    ~MySlider()
    {
    }

    void mouseDown
    ( const MouseEvent& e )
    {
        Slider::mouseDown(e);

        setMouseCursor(MouseCursor::NoCursor);
        updateMouseCursor();
        // We need to hide the cursor via Windows API as well to have it
        // disappear immediately.
        SetCursor(0); 
    };

    void mouseUp
    ( const MouseEvent& e )
    {
        Slider::mouseUp(e);

        setMouseCursor(MouseCursor::NormalCursor);
        updateMouseCursor();
    };
};