AniLoad




Option Explicit
'Main cursor constant

Public Const GCL_HCURSOR = (-12)

'Loads cursor from A FILE and creates mouse pointer handle

Public Declare Function LoadCursorFromFile _
Lib "User32" Alias "LoadCursorFromFileA" _
(ByVal lpFileName As String) As Long

'Changes class information for a window


Public Declare Function SetClassLong _
Lib "User32" Alias "SetClassLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long

'Get TEMP directory of current OS


Public Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long

Option Explicit
'old handle of load cursor

Private hOldCursor As Long
'new handle of loaded cursor

Private hNewCursor As Long
'bytes array holding binary data of Animated Cursor file

Private bufAniCursor() As Byte
'temporary directory of current OS

Private sTmpPath As String
'on form loading


Private Sub Form_Load()
'available file number to open

Dim iFileNumOut As Integer
'load custom animated cursor from resource file, get its bytes array

bufAniCursor = LoadResData(101, "CUSTOM")
'get available file number to open

iFileNumOut = FreeFile
'initialize string variable receiving OSTEMP directory path

sTmpPath = Space$(1000)
'Get OS TEMP directory path

GetTempPath 1000, sTmpPath
'trim string variable containing TEMP Directory path

sTmpPath = Trim(sTmpPath)
'since it's a null-terminated string, get rid of the last character

sTmpPath = Left$(sTmpPath, Len(sTmpPath) - 1)
'create a binary file in the temp directory, name it as you wish

Open sTmpPath & "Custom.ani" For Binary Access Write As #iFileNumOut
'Copy bytes data of loaded cursor onto file

Put #iFileNumOut, , bufAniCursor
Close #iFileNumOut
'get cursor handle from loading existingcursor from OS temp path

hNewCursor = LoadCursorFromFile(sTmpPath & "Custom.ani")
'store old cursor handle, and set new custom mouse pointer

hOldCursor = SetClassLong(Me.hwnd, GCL_HCURSOR, hNewCursor)
Me.MousePointer = 99
End Sub

'before unloading form


Private Sub Form_Unload(Cancel As Integer)
'restore old cursor handle

hOldCursor = SetClassLong(Me.hwnd, GCL_HCURSOR, hOldCursor)
Me.MousePointer = vbNormal
'optional, temporary created file: kill it before it grows

Kill sTmpPath & "Custom.ani"
End Sub
Inputs:
Temporary directory path of you OS












( aniload.html )- by Paolo Puglisi - Modifica del 17/12/2023