Author Topic: Hiding the mouse cursor - INLINE, user32 DLL option?  (Read 2606 times)

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 361
  • Aoooooooo - the werewolves of London!
    • View Profile
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?

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
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
« Last Edit: 2021-Jan-20 by Qedo »

Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile
   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

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 361
  • Aoooooooo - the werewolves of London!
    • View Profile
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.

Offline Schranz0r

  • Premium User :)
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 5116
  • O Rly?
    • View Profile
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

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 361
  • Aoooooooo - the werewolves of London!
    • View Profile
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????




Offline Qedo

  • Dr. Type
  • ****
  • Posts: 389
  • to program what I have do how should programming?
    • View Profile

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10859
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 361
  • Aoooooooo - the werewolves of London!
    • View Profile
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.

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 361
  • Aoooooooo - the werewolves of London!
    • View Profile
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.

Offline hardyx

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 505
    • View Profile
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)

Offline Darmakwolf

  • Dr. Type
  • ****
  • Posts: 361
  • Aoooooooo - the werewolves of London!
    • View Profile
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 -_-
« Last Edit: 2021-Jan-26 by Darmakwolf »