Hiding the mouse cursor - INLINE, user32 DLL option?

Previous topic - Next topic

Darmakwolf

Hi all! I am working on a project and here's my conundrum. I want to display my own cursor, but I don't want the system cursor displaying over it. I know I can do SYSTEMPOINTER FALSE, but then the mouse is locked to the window. If I could maybe invoke user32.dll (SetSystemCursor?) - perhaps we can do SYSTEMPOINTER TRUE and invoke this dll call to tell Windows to hide the system cursor while in our app, we can achieve this. Thoughts? Anyone able to help?

Qedo

so it can work ?

   LOADSPRITE "Media/yourpointer.png", 0
   LOCAL mx, my, b1, b2
    SYSTEMPOINTER FALSE
      REPEAT
         MOUSESTATE mx, my, b1, b2
         DRAWSPRITE 0,mx,my
         SHOWSCREEN
      UNTIL FALSE   
   END

ad maiora

Qedo

   or better:

   LOADSPRITE "Media/Caricatore.png", 0
   LOCAL mx, my, b1, b2,sx,sy
    SYSTEMPOINTER TRUE
    GETSCREENSIZE sx,sy
      REPEAT
         MOUSESTATE mx, my, b1, b2
         IF mx>0 AND mx < sx AND my>0 AND my < sy
            SYSTEMPOINTER FALSE
         ELSE
            SYSTEMPOINTER TRUE
         ENDIF
         DRAWSPRITE 0,mx,my
         SHOWSCREEN
      UNTIL FALSE
   END

ad maiora

Darmakwolf

No. The ol' "if outside screen, systempointer true" used to work on windows 7 and older. On 8 and newer the mouse gets stuck unless you the program in compatibility mode. The real solution here would be to invoke Windows API to hide the mouse CURSOR. When GLBasic does it, it GRABS the mouse and doesn't let it out of the bounding box until you turn that off, but then you have the mouse cursor over custom cursor issue again. Not a solution, but thank you. Just looking for someone's help WRAPPING USER32.DLL TO HIDE THE MOUSE.

Schranz0r

If the Pointer is shown with SYSTEMPOINTER FALSE it's sounds like a bug to me...
So i move the topic to bugreport! :)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Darmakwolf

Quote from: Schranz0r on 2021-Jan-22
If the Pointer is shown with SYSTEMPOINTER FALSE it's sounds like a bug to me...
So i move the topic to bugreport! :)


Gah.. sorry. No. Not the issue.

SYSTEMPOINTER TRUE: I can use the mouse and it's not locked to a window. Fine.
SYSTEMPOINTER FALSE: I am locked to the window and can't move the mouse outside of it.

MY PROBLEM: I want to use a game-drawn mouse. I am either stuck with the system (windows) mouse drawn OVER my custom cursor if I want mouse freedom to leave the game window, or I am stuck with being able to use a custom drawn cursor rendered by the game BUT LOCKED TO THE GAME WINDOW.

WHY for the love of god can I not draw my own cursor and have the freedom to move the mouse OUTSIDE THE GAME WINDOW without the Windows system cursor being drawn over it. This isn't a BUG - it's a missing feature.

All I am asking is some help wrapping user32.dll to hide the mouse cursor so I can do SYSTEMPOINTER TRUE, draw my custom cursor, and hide the windows cursor. That's it!

Gernot????




Qedo


Kitty Hello


Darmakwolf

Quote from: Kitty Hello on 2021-Jan-23
Try Setcursor(0):
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setcursor
It might work with the IMPORT command.

Gernot, can you help me with the glbasic wrapper to call this? Having trouble with that.

Darmakwolf

Quote from: Kitty Hello on 2021-Jan-23
Try Setcursor(0):
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setcursor
It might work with the IMPORT command.

in addition, Gernot, I found the following:

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setsystemcursor

I think this is more what we want? I think SetCursor is momentary, per some googling, not "while in app window." Not sure how to experiment with it. I just want a custom drawn cursor in the game without being locked to a screen and no windows mouse covering it up.

hardyx

I think you can use Win32 functions declaring with the IMPORT command and calling.

Code (glbasic) Select

// If the hCursor is NULL, the cursor is removed from the screen.
IMPORT "C" void* __stdcall SetCursor(void* hCursor)

// hide windows cursor
SetCursor(0)


Darmakwolf

Quote from: hardyx on 2021-Jan-26
I think you can use Win32 functions declaring with the IMPORT command and calling.

Code (glbasic) Select

// If the hCursor is NULL, the cursor is removed from the screen.
IMPORT "C" void* __stdcall SetCursor(bool* hCursor)

// hide windows cursor
SetCursor(0)


Problem solved! Thanks to your help with IMPORT. I found that SetCursor only hides the mouse *temporarily* every time it's called. However,
I found:

IMPORT "C" void* __stdcall ShowCursor(int bShow)

and you simply call it with ShowCursor(0)


Set SYSTEMPOINTER TRUE
This produces the desired behavior! The system mouse is hidden while inside the glbasic window, and shown while outside of it. I can draw my own cursor on-screen with drawsprite/anim, and it tracks properly.

woohoo - thank you!

Now if I could just get MOUSEAXIS(2) working, per my other post -_-