The Windows API provides a few functions that allow applications to modify the cursor on the fly. SetCursor is used in conjunction with SetCapture for events where the user clicks and drags the mouse beyond the boundaries of the window. The default cursor for a window is set when RegisterClass is called for the window but it can also be updated by calling SetWindowClass.
For this example if you have the window selected pressing the "Q" key will change the cursor to a walking dinosaur (if you have the cursor \windows\cursors\dinosaur.ani which should come with XP and Vista). The "W" key will change it back to the arrow. This is using the SetWindowClass method. If you hold the left mouse button down inside the window and drag anywhere on your screen you will see an example of the SetCursor method.
Code: Select all
Enumeration
#Main_Window
EndEnumeration
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Shared PrevWndFunc
Select uMsg
Case #WM_KEYDOWN
If wParam=#VK_Q
WindowsPath.s=Space(#MAX_PATH)
GetWindowsDirectory_(@WindowsPath.s,#MAX_PATH)
hCursor=LoadCursorFromFile_(WindowsPath.s+"\Cursors\dinosaur.ani")
SetClassLong_(WindowID(#Main_Window),#GCL_HCURSOR,hCursor)
ElseIf wParam=#VK_W
SetClassLong_(WindowID(#Main_Window),#GCL_HCURSOR,LoadCursor_(0,#IDC_ARROW))
EndIf
Case #WM_LBUTTONDOWN
SetCapture_(hWnd)
hCursor=LoadCursor_(0,#IDC_HELP)
SetCursor_(hCursor)
Case #WM_LBUTTONUP
ReleaseCapture_()
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
OpenWindow(#Main_Window,0,0,160,120,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowCallback(@WinCallback())
Repeat
Until WaitWindowEvent()=#WM_CLOSE