Option Explicit
Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Private Declare Function SetSystemCursor Lib "user32" (ByVal hcur As Long, ByVal id As Long) As Long
Private Declare Function GetCursor Lib "user32" () As Long
Private Declare Function CopyIcon Lib "user32" (ByVal hIcon As Long) As Long
Private Const OCR_NORMAL As Long = 32512
Private curseurpresent As Long
Private iconcurseurpresent As Long
Private Sub Command1_Click()
'===================je récupère d'abord (pour pouvoir au besoin le restituer) le curseur en cours
curseurpresent = GetCursor()
iconcurseurpresent = CopyIcon(curseurpresent)
'=================================================================
Dim myDir As String
Dim lDir As Long
myDir = Space(255)
lDir = GetWindowsDirectory(myDir, 255)
myDir = Left$(myDir, lDir) & "\cursors\"
CommonDialog1.InitDir = myDir
CommonDialog1.ShowOpen
definitcurseur CommonDialog1.filename
End Sub
Private Sub Form_Activate()
Command1.Caption = "choisir un curseur"
End Sub
Sub definitcurseur(lefic)
Dim lecurseur As Long
lecurseur = LoadCursorFromFile(lefic)
Call SetSystemCursor(lecurseur, OCR_NORMAL)
End Sub
Private Sub Form_Unload(Cancel As Integer)
'========= je restitue le curseur tel qu'il était
Call SetSystemCursor(iconcurseurpresent, OCR_NORMAL)
End Sub