Page 1 of 1
Hide cursor over specific gadget
Posted: Fri Jul 23, 2010 12:19 am
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?
Re: Hide cursor over specific gadget
Posted: Fri Jul 23, 2010 1:21 am
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.
Re: Hide cursor over specific gadget
Posted: Fri Jul 23, 2010 1:39 am
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
Re: Hide cursor over specific gadget
Posted: Fri Jul 23, 2010 3:11 am
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?
Re: Hide cursor over specific gadget
Posted: Sat Jul 24, 2010 3:22 am
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.
Re: Hide cursor over specific gadget
Posted: Thu Jul 29, 2010 9:46 am
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.