Page 1 of 1

[SOLVED] Switch mouse cursor from arrow to hand

Posted: Mon Dec 08, 2025 2:39 pm
by Joubarbe
Is there any way to change (temporarily) the mouse cursor while using hardware mouse and a windowed screen? (on Windows)

Code: Select all

SetClassLong_(hWnd, #GCL_HCURSOR, LoadCursor_(0, #IDC_HAND))
This doesn't work.

SOLVED:

Code: Select all

SetClassLongPtr_(WindowID(0), #GCL_HCURSOR, 0)
SetCursor_(LoadCursor_(0, #IDC_HAND))

Re: Switch mouse cursor from arrow to hand

Posted: Tue Dec 09, 2025 10:50 am
by Axolotl
Please try

Code: Select all

setcursor_(hCursor)
BTW: there are a lot of examples around. Just search for setcursor_

Re: Switch mouse cursor from arrow to hand

Posted: Tue Dec 09, 2025 4:18 pm
by Joubarbe
The problem is that it's very glitchy when used with a screen:

Code: Select all

If InitSprite() = #Null
  MessageRequester("Error", "InitSprite failed.", #PB_MessageRequester_Error)
  End
EndIf

#_WINDOW_WIDTH = 720
#_WINDOW_HEIGHT = 640
OpenWindow(0, 0, 0, #_WINDOW_WIDTH, #_WINDOW_HEIGHT, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, #_WINDOW_WIDTH, #_WINDOW_HEIGHT)

CreateSprite(0, 100, 100, #PB_Sprite_AlphaBlending)

Repeat
  
  Repeat
    Define event = WindowEvent()
    
    Select event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until event = #Null
  
  FlipBuffers() 
  ClearScreen(#Black)
  
  If WindowMouseX(0) >= 0 And WindowMouseX(0) < 100 And WindowMouseY(0) >= 0 And WindowMouseY(0) < 100
    DisplayTransparentSprite(0, 0, 0, 255, #Green)
    SetCursor_(LoadCursor_(0, #IDC_HAND))
  Else
    DisplayTransparentSprite(0, 0, 0, 255, #Gray)
    SetCursor_(LoadCursor_(0, #IDC_ARROW))
  EndIf
  
  Delay(1)
  
ForEver

Re: Switch mouse cursor from arrow to hand

Posted: Tue Dec 09, 2025 6:15 pm
by RASHAD

Code: Select all

If InitSprite() = #Null
  MessageRequester("Error", "InitSprite failed.", #PB_MessageRequester_Error)
  End
EndIf

#_WINDOW_WIDTH = 720
#_WINDOW_HEIGHT = 640
OpenWindow(0, 0, 0, #_WINDOW_WIDTH, #_WINDOW_HEIGHT, "", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, #_WINDOW_WIDTH, #_WINDOW_HEIGHT)

CreateSprite(0, 100, 100, #PB_Sprite_AlphaBlending)

Repeat
  
  Repeat
    Define event = WindowEvent()
    
    Select event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until event = #Null
  
  FlipBuffers() 
  ClearScreen(#Black)
  
  If WindowMouseX(0) >= 0 And WindowMouseX(0) < 100 And WindowMouseY(0) >= 0 And WindowMouseY(0) < 100
    DisplayTransparentSprite(0, 0, 0, 255, #Green)
    SetClassLongPtr_(WindowID(0), #GCL_HCURSOR, 0)
    SetCursor_(LoadCursor_(0, #IDC_HAND))
  Else
    DisplayTransparentSprite(0, 0, 0, 255, #Gray)
    SetClassLongPtr_(WindowID(0), #GCL_HCURSOR, 0)
    SetCursor_(LoadCursor_(0, #IDC_ARROW))
  EndIf
  
  Delay(1)
  
ForEver


Re: Switch mouse cursor from arrow to hand

Posted: Tue Dec 09, 2025 6:23 pm
by Joubarbe
Thank you RASHAD! :)