I'm in need of a solution whereby I can control the cursor icon/design during runtime. A solution that will be cross-compatible between Linux and Windows without having to make adjustments to the code...
So I started writing a module specifically for that purpose and would like to share the progress with you:
So far it works well on the Windows environment (hopefully I can get confirmation of this with other versions of Windows as I'm testing on Win 7), and over time I hope to include more cursor styles and of course the all-important GTK implementation. If you folks have any suggestions or ideas then please do share

(Current Revision: 1)
Code: Select all
; ====================================================================================================
; Title: UI Cursor Module
; Description: Enable the changing of the mouse cursor style.
; Target OS: Windows, Linux [GTK] (TODO)
; Author: IndigoFuzz
; Contributors: You name here?
; Revision: 1
; Notes: When cursor leaves bounding of window/gadget then cursor will be reset.
; ====================================================================================================
; TODO LIST
; Implement more cursor styles.
; Begin implementation of GTK code.
DeclareModule UICursor
Enumeration CursorID
#Cursor_Arrow
;#Cursor_RightArrow
;#Cursor_Bullseye
;#Cursor_Char
#Cursor_Cross
#Cursor_Hand
#Cursor_IBeam
;#Cursor_LeftButton
;#Cursor_Magnifier
;#Cursor_MiddleButton
#Cursor_NoEntry
;#Cursor_PaintBrush
;#Cursor_Pencil
;#Cursor_PointLeft
;#Cursor_PointRight
#Cursor_QuestionArrow
;#Cursor_RightButton
#Cursor_SizeNESW
#Cursor_SizeNS
#Cursor_SizeNWSE
#Cursor_SizeWE
#Cursor_Sizing
;#Cursor_SprayCan
#Cursor_Wait
;#Cursor_Watch
;#Cursor_Blank
#Cursor_ArrowWait
#Cursor_Count
EndEnumeration
Declare SetCursor(*WindowID, Cursor = #Cursor_Arrow)
Declare ReleaseAll()
EndDeclareModule
Module UICursor
EnableExplicit
; Private:
Structure modData
*pCursor[#Cursor_Count]
EndStructure
Global _inst.modData
Procedure _loadCursor(ID)
Protected stockID.i = 0
With _inst
If \pCursor[ID] = #Null
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Select ID
Case #Cursor_Arrow
\pCursor[ID] = LoadCursor_(0, #IDC_ARROW)
;Case #Cursor_RightArrow
;Case #Cursor_Bullseye
;Case #Cursor_Char
Case #Cursor_Cross
\pCursor[ID] = LoadCursor_(0, #IDC_CROSS)
Case #Cursor_Hand
\pCursor[ID] = LoadCursor_(0, #IDC_HAND)
Case #Cursor_IBeam
\pCursor[ID] = LoadCursor_(0, #IDC_IBEAM)
;Case #Cursor_LeftButton
;Case #Cursor_Magnifier
;Case #Cursor_MiddleButton
Case #Cursor_NoEntry
\pCursor[ID] = LoadCursor_(0, #IDC_NO)
;Case #Cursor_PaintBrush
;Case #Cursor_Pencil
;Case #Cursor_PointLeft
;Case #Cursor_PointRight
Case #Cursor_QuestionArrow
\pCursor[ID] = LoadCursor_(0, #IDC_HELP)
;Case #Cursor_RightButton
Case #Cursor_SizeNESW
\pCursor[ID] = LoadCursor_(0, #IDC_SIZENESW)
Case #Cursor_SizeNS
\pCursor[ID] = LoadCursor_(0, #IDC_SIZENS)
Case #Cursor_SizeNWSE
\pCursor[ID] = LoadCursor_(0, #IDC_SIZENWSE)
Case #Cursor_SizeWE
\pCursor[ID] = LoadCursor_(0, #IDC_SIZEWE)
Case #Cursor_Sizing
\pCursor[ID] = LoadCursor_(0, #IDC_SIZEALL)
;Case #Cursor_SprayCan
Case #Cursor_Wait
\pCursor[ID] = LoadCursor_(0, #IDC_WAIT)
;Case #Cursor_Watch
;Case #Cursor_Blank
Case #Cursor_ArrowWait
\pCursor[ID] = LoadCursor_(0, #IDC_APPSTARTING)
EndSelect
CompilerCase #PB_OS_Linux
Select ID
Case #Cursor_Arrow
;Case #Cursor_RightArrow
;Case #Cursor_Bullseye
;Case #Cursor_Char
Case #Cursor_Cross
Case #Cursor_Hand
Case #Cursor_IBeam
;Case #Cursor_LeftButton
;Case #Cursor_Magnifier
;Case #Cursor_MiddleButton
Case #Cursor_NoEntry
;Case #Cursor_PaintBrush
;Case #Cursor_Pencil
;Case #Cursor_PointLeft
;Case #Cursor_PointRight
Case #Cursor_QuestionArrow
;Case #Cursor_RightButton
Case #Cursor_SizeNESW
Case #Cursor_SizeNS
Case #Cursor_SizeNWSE
Case #Cursor_SizeWE
Case #Cursor_Sizing
;Case #Cursor_SprayCan
Case #Cursor_Wait
;Case #Cursor_Watch
;Case #Cursor_Blank
Case #Cursor_ArrowWait
EndSelect
CompilerEndSelect
EndIf
EndWith
EndProcedure
Procedure _applyCursor(*WindowID, Cursor)
With _inst
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
If \pCursor[Cursor]
SetClassLong_(*WindowID, #GCL_HCURSOR, 0)
SetCursor_(\pCursor[Cursor])
EndIf
CompilerCase #PB_OS_Linux
CompilerEndSelect
EndWith
EndProcedure
; Public:
Procedure SetCursor(*WindowID, Cursor = #Cursor_Arrow)
If Cursor > -1 And Cursor < #Cursor_Count
If *WindowID <> 0
_loadCursor(Cursor)
_applyCursor(*WindowID, Cursor)
EndIf
EndIf
EndProcedure
Procedure ReleaseAll()
With _inst
Protected ix.i
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
For ix = 0 To (#Cursor_Count - 1)
If \pCursor[ix]
DestroyCursor_(\pCursor[ix])
EndIf
Next
CompilerEndSelect
EndWith
EndProcedure
EndModule
; =============
; == EXAMPLE ==
; =============
; - Create Window -
OpenWindow(0, #PB_Ignore, #PB_Ignore, 500, 300, "Cursor Test", #PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 480, 280, "Cursors", 475)
; - Populate List -
AddGadgetItem(0, -1, "#Cursor_Arrow")
;AddGadgetItem(0, -1, "#Cursor_RightArrow")
;AddGadgetItem(0, -1, "#Cursor_Bullseye")
;AddGadgetItem(0, -1, "#Cursor_Char")
AddGadgetItem(0, -1, "#Cursor_Cross")
AddGadgetItem(0, -1, "#Cursor_Hand")
AddGadgetItem(0, -1, "#Cursor_IBeam")
;AddGadgetItem(0, -1, "#Cursor_LeftButton")
;AddGadgetItem(0, -1, "#Cursor_Magnifier")
;AddGadgetItem(0, -1, "#Cursor_MiddleButton")
AddGadgetItem(0, -1, "#Cursor_NoEntry")
;AddGadgetItem(0, -1, "#Cursor_PaintBrush")
;AddGadgetItem(0, -1, "#Cursor_Pencil")
;AddGadgetItem(0, -1, "#Cursor_PointLeft")
;AddGadgetItem(0, -1, "#Cursor_PointRight")
AddGadgetItem(0, -1, "#Cursor_QuestionArrow")
;AddGadgetItem(0, -1, "#Cursor_RightButton")
AddGadgetItem(0, -1, "#Cursor_SizeNESW")
AddGadgetItem(0, -1, "#Cursor_SizeNS")
AddGadgetItem(0, -1, "#Cursor_SizeNWSE")
AddGadgetItem(0, -1, "#Cursor_SizeWE")
AddGadgetItem(0, -1, "#Cursor_Sizing")
;AddGadgetItem(0, -1, "#Cursor_SprayCan")
AddGadgetItem(0, -1, "#Cursor_Wait")
;AddGadgetItem(0, -1, "#Cursor_Watch")
;AddGadgetItem(0, -1, "#Cursor_Blank")
AddGadgetItem(0, -1, "#Cursor_ArrowWait")
SetGadgetState(0, 0)
; - Loop Entry Point -
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0 And GetGadgetState(0) > -1
UICursor::SetCursor(GadgetID(0), GetGadgetState(0))
EndIf
EndSelect
ForEver
CloseWindow(0)
UICursor::ReleaseAll()