Hide cursor over specific gadget

Just starting out? Need help? Post your questions and find answers here.
User avatar
kenmo
Addict
Addict
Posts: 2042
Joined: Tue Dec 23, 2003 3:54 am

Hide cursor over specific gadget

Post by kenmo »

I know you can use ShowCursor_() to hide the mouse cursor over a window, but is there a simple way to hide it only when it is over a certain gadget?

I'm wondering what the simplest method would be, and Windows-only is fine (I'm writing an MDI based program).

Ideas?
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Hide cursor over specific gadget

Post by IdeasVacuum »

Hi Kenmo

Here is one way. In a Repeat loop, test for the cursor position:

Code: Select all

iCursorX =   WindowMouseX(#WIN)
iCursorY =   WindowMouseY(#WIN)
Then test to see if the cursor is inside the 'hot spot' where you don't want it displayed (unusual?) or want to change the cursor graphic:

Code: Select all

If (iCursorX > 15) And (iCursorX < 75) And (iCursorY > 20) And (iCursorY < 40)

                 SetCursor_(ighHandCursor)

 ElseIf (iCursorX > 750) And (iCursorX < 771) And (iCursorY > 20) And (iCursorY < 40)

                  SetCursor_(ighHandCursor)

Else
                  SetCursor_(ighCrossCursor)

 EndIf
The above is not a working code snippet, just a guide to the method.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: Hide cursor over specific gadget

Post by netmaestro »

Code: Select all

Procedure SubClassProc(hwnd, msg, wparam, lparam)
  oldproc = GetProp_(hwnd, "oldproc")
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, "oldproc")
      
    Case #WM_SETCURSOR
      SetCursor_(0)
      ProcedureReturn 0
    
  EndSelect   
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure


OpenWindow(0,0,0,800,600,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
hwnd = ImageGadget(0,100,100,0,0,LoadImage(0, #PB_Compiler_Home+"Examples\sources\data\background.bmp"))
SetProp_(hwnd, "oldproc", SetWindowLongPtr_(hwnd, #GWL_WNDPROC, @SubClassProc()))

Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow


BERESHEIT
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Hide cursor over specific gadget

Post by IdeasVacuum »

That is a very nice way netmaestro.
To handle more than one gadget:

Code: Select all

Procedure SubClassProc(hwnd, msg, wparam, lparam)
  oldproc = GetProp_(hwnd, msg)
  Select msg
    Case #WM_NCDESTROY
      RemoveProp_(hwnd, msg)
     
    Case #WM_SETCURSOR
      SetCursor_(0)
      ProcedureReturn 0
   
  EndSelect   
  ProcedureReturn CallWindowProc_(oldproc, hwnd, msg, wparam, lparam)
EndProcedure
It's feels a bit weird to lose your cursor though! What is the benefit of hiding the cursor over a gadget kenmo?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
kenmo
Addict
Addict
Posts: 2042
Joined: Tue Dec 23, 2003 3:54 am

Re: Hide cursor over specific gadget

Post by kenmo »

I have an ImageGadget that is updated in near-realtime and draws at the cursor position... I just don't want the Windows cursor to be over it.

Thanks for the examples guys, I'll give them a try.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Hide cursor over specific gadget

Post by IdeasVacuum »

Oh I see. Perhaps you could 'park' the cursor away from the action, or offset it's location by a few pixels, or change the cursor to cross-hair so that it does not obscure so much.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply