Keep in mind that this is NOT the correct way to hide the user's mouse but it's useful in a pinch where Win32 SetCapture is not available such as when the hWnd not owned by your process. See the SetCapture documentation:
Despite finding a constant for IDC_ALTSELECT, I was not able to find a way to hide the "Alternate Select" cursor (the right-facing cursor typically used in code editor gutters).Sets the mouse capture to the specified window belonging to the current thread.
Any help finding this constant would be appreciated.
h.HideCursor.pb:
Code: Select all
#IDC_PEN=32631
#IDC_WAITCD=32663
#IDC_ALTSELECT=32501
Structure Glob_HideCursor
Array CursorIdentifiers.i(19)
Array CurcorCache.i(19)
InvisibleCursor.i
EndStructure
Global Glob_HideCursor.Glob_HideCursor
Declare HideCursor(Hidden=#True, UpdateCache=#False)
If Not Glob_HideCursor\InvisibleCursor
;/ Create an invisible cursor
AndMask=AllocateMemory(32*4)
FillMemory(AndMask,32*4,$FF)
XorMask=AllocateMemory(32*4)
Glob_HideCursor\InvisibleCursor=CreateCursor_(0,0,0,32,32,AndMask,XorMask)
FreeMemory(AndMask)
FreeMemory(XorMask)
;/ Build an array of common system cursor identifiers
Restore CursorIdentifiers
For i=1 To 19
Read.i Glob_HideCursor\CursorIdentifiers(i-1)
Next i
EndIf
DataSection
CursorIdentifiers:
Data.i #IDC_APPSTARTING
Data.i #IDC_ARROW
Data.i #IDC_CROSS
Data.i #IDC_HAND
Data.i #IDC_HELP
Data.i #IDC_IBEAM
Data.i #IDC_ICON
Data.i #IDC_NO
Data.i #IDC_SIZE
Data.i #IDC_SIZEALL
Data.i #IDC_SIZENESW
Data.i #IDC_SIZENS
Data.i #IDC_SIZENWSE
Data.i #IDC_SIZEWE
Data.i #IDC_UPARROW
Data.i #IDC_WAIT
Data.i #IDC_PEN
Data.i #IDC_WAITCD
Data.i #IDC_ALTSELECT
EndDataSection
EnableExplicit
XIncludeFile #PB_Compiler_File+"\..\"+"lib.HideCursor.pb"
DisableExplicit
Code: Select all
Procedure HideCursor(Hidden=#True, UpdateCache=#False)
Protected hCursor
Protected i
;/ Inititalize at first call or update cache on request
If UpdateCache Or Not Glob_HideCursor\CurcorCache(0)
;/ Store a copy of cursors currently in use
For i=1 To 19
;/ Destroy any previously cached cursors
If Glob_HideCursor\CurcorCache(i-1)
DestroyCursor_(Glob_HideCursor\CurcorCache(i-1))
EndIf
hCursor=LoadCursor_(0,Glob_HideCursor\CursorIdentifiers(i-1))
Glob_HideCursor\CurcorCache(i-1)=CopyImage_(hCursor,2,0,0,0)
;/ Destroy the temporary cursor
DestroyCursor_(hCursor)
Next i
EndIf
For i=1 To 19
If Hidden
hCursor=CopyImage_(Glob_HideCursor\InvisibleCursor,2,0,0,0)
Else
hCursor=CopyImage_(Glob_HideCursor\CurcorCache(i-1),2,0,0,0)
EndIf
SetSystemCursor_(hCursor,Glob_HideCursor\CursorIdentifiers(i-1))
Next i
EndProcedure
Code: Select all
;/ Hide the cursor for two seconds
HideCursor(#True)
Delay(2000)
HideCursor(#False)