=Custom Cursors With LoadCursorFromFile= 
//Janet Terra//
[[toc|flat]]
----
=Changing the Cursor= 
Mitchell Kotler wrote two articles for the Liberty BASIC Newsletters about loading Windows cursors using the 16 bit user.dll, "LoadCursor" API.  The demo was written for Liberty BASIC v2.  As an update to Liberty BASIC v4.x and the 32 bit user32.dll, Gordon Sweet submitted [[newsletter.2004#x--Issue%20#121%20Jun.%202004|Changing the Cursor - Two Examples]] for the Liberty BASIC Newsletter #121.  These programs temporarily change the cursor to any of 25 predefined Windows images.  It is possible to temporarily change the cursor to a custom designed cursor using the user32.dll, "LoadCursorFromFile" API.

=Finding Custom Cursors=
This article originally appeared in the Liberty BASIC Newsletters #135 and was based upon information valid for Windows XP.  The available cursors and cursor names differ in Windows 7.  In either version, the cursor files are found in the C:\WINDOWS\Cursors\ directory.  You may need to adjust the variable path$ if your Windows path differs.  This demo loads four cursors found in the Windows\Cursors\ folder.  In addition, four custom cursors, can be loaded and used.  The cursors were obtained from these websites

=Setting the Cursor in the Control Panel= 
My Computer> Control Properties> Mouse> Pointers brings up a dialog that will allow you to change the Mouse Pointer scheme.  You can search the web to find numerous libraries of cursors in just about every theme imaginable. **<span style="color: #ff0000;">This demo DOES NOT alter or add to your computer mouse settings</span>**.

=SetCursor vs SetSystemCursor=
The code in this demo temporarily changes the cursor while it is over the graphicbox only.  Each time the mouse moves, the call to SetCursor must be made.  The cursor reverts to the original when not moving over the graphicbox. It is possible to permanently change the look of the cursor with the API call, SetSystemCursor.  Be careful, though, as this call can make irreversible and unpleasant changes.  **<span style="color: #ff0000;">This demo DOES NOT call SetSystemCursor</span>**.

=Static Cursors and Animated Cursors=
Static cursors end with the extension **.cur**.  An animated cursor usually ends with the extension **.avi**.  Both are loaded with the user32.dll "LoadCursorFromFile" API call.  This demo displays both static and animated cursors.  Use the Menu to sample the different icons.

[[code format="lb"]]
'Demo by Janet Terra
'Originally published Liberty BASIC Newsletter #135
'Updated July, 2011, for LBPE
'Requires BlueTranspCircle.cur, GreenTranspCircle.cur, LumaBlue.ani, LumaGreen.ani
'or substitute with your own cursor files

    Nomainwin
    Dim StyleCursor(8)
    path$ = "C:\WINDOWS\Cursors\" 'Cursors following path$ found in Windows Directory
    StyleCursor$(1) = path$;"lnesw.cur"
    StyleCursor$(2) = path$;"hnwse.cur"
    StyleCursor$(3) = path$;"hnesw.cur"
    StyleCursor$(4) = path$;"hnodrop.cur"
    StyleCursor$(5) = "BlueTranspCircle.cur"
    StyleCursor$(6) = "GreenTranspCircle.cur"
    StyleCursor$(7) = "LumaBlue.ani"
    StyleCursor$(8) = "LumaGreen.ani"

    WindowWidth = 308
    WindowHeight = 368
    UpperLeftX = Int((DisplayWidth - WindowWidth)/2)
    UpperLeftY = Int((DisplayHeight - WindowHeight)/2)

    msg$ = "  Move Mouse Over "
    Menu #main, "Cursors", "Windows - Pointing Hand", _
        [cursor1], "Windows - Hand Slanted Left", _
        [cursor2],  "Windows - Hand Slanted Right", [cursor3], _
        "Windows - Hand No Drop", [cursor4],|, _
        "Custom - Blue Circle", [cursor5], "Custom - Green Circle", _
        [cursor6],|, "Custom Animated - Luma Blue", [cursor7], _
        "Custom Animated - Luma Green", [cursor8],|, "Normal", _
        [cursor0],|, "E&xit", [endDemo]

    Graphicbox #main.g, 0, 0, 300, 100
    Statictext #main.s, "", 0, 110, 300, 100
    Stylebits #main.s, _SS_CENTERIMAGE, 0, 0, 0
    Textbox #main.t, 0, 220, 300, 100
    Stylebits #main.t, _ES_READONLY or _ES_MULTILINE, _ES_AUTOHSCROLL, 0, 0
    Open "Load Cursor From File" for Window_NF as #main
    #main, "Trapclose [endDemo]"
    hMain = hWnd(#main)
    hGB = hWnd(#main.g)
    Call SetClass hGB

'Text Messages to User
    #main, "Font Microsoft_Sans_Serif 12 Bold"
    #main.g, "Font Microsoft_Sans_Serif 12 Bold"
    #main.g, "Down; Fill Yellow; Color Darkgreen; Backcolor Yellow"
    #main.g, "\\\\";msg$;"Graphic Window"
    #main.g, "Flush"
    #main.s, msg$;"Regular Window"
    #main.t, Chr$(13);Chr$(10);Chr$(13);Chr$(10);msg$;"Textbox"

'Trapping When mouseMove"
    #main.g, "When mouseMove [showCursor]"
    #main.g, "Setfocus"

[cursor0]
    cursorHandle = _OCR_NORMAL
    Wait

[cursor1]
    cursorFile$ = StyleCursor$(1)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[cursor2]
    cursorFile$ = StyleCursor$(2)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[cursor3]
    cursorFile$ = StyleCursor$(3)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[cursor4]
    cursorFile$ = StyleCursor$(4)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[cursor5]
    cursorFile$ = StyleCursor$(5)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[cursor6]
    cursorFile$ = StyleCursor$(6)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[cursor7]
    cursorFile$ = StyleCursor$(7)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[cursor8]
    cursorFile$ = StyleCursor$(8)
    cursorHandle = LoadCursorFromFile(cursorFile$)
    Wait

[showCursor]
    Call SetCursor cursorHandle
    Wait

[endDemo]
    Close #main
    End

'Call just once in the beginning of the program
    Sub SetClass hWin
        index = _GCL_HCURSOR or 0
        value = 0
        CallDLL #user32, "SetClassLongA", _
            hWin as Long, _
            index as Long, _
            value as Long, _
            result as Long
    End Sub

'Set Cursor to Handle of Loaded Cursor
    Sub SetCursor hCursor
        CallDLL #user32, "SetCursor", _
            hCursor as long, _
            result as long
    End Sub

'Load Cursor from File
    Function LoadCursorFromFile(file$)
        CallDLL #user32, "LoadCursorFromFileA", _
        file$ as Ptr, _
        LoadCursorFromFile as Long
    End Function
[[code]]

----
[[toc|flat]]