i found these function in net for read animated cursors, but the real one change the system cursor. but i wanted put(draw) the subimages in a picturebox array.
in my new changes i have incompleted DrawIconEx(i don't know use these API function) arguments.
and i don't know if there is more errors.
can anyone help me finish these function?
Code:
Option Explicit
Private Declare Function LoadCursorFromFile Lib "user32" Alias _
"LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Private Declare Function GetCursor Lib "user32" () As Long
Private Declare Function CopyIcon Lib "user32" (ByVal hcur As Long) As Long
Private mlngOldCursor As Long, lngNewCursor As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Public Sub AnimatedCursor(AniFilePath As String, picDestany As Variant)
Static i As Long
i = i + 1
'Create a copy of the current cursor, 'for Windows NT compatibility
mlngOldCursor = CopyIcon(GetCursor())
'Check the passed string, if it contains
'a solid file path, then load the cursor
'from file. If not, add the App.Path, '*then* load cursor...
If InStr(1, AniFilePath, "\") Then
lngNewCursor = LoadCursorFromFile(AniFilePath)
Else
lngNewCursor = LoadCursorFromFile(App.Path & _
"\" & AniFilePath)
End If 'Activate the cursor
Load picDestany(i)
drawiconex picDestany(i).hdc,0,0, lngNewCursor,
End Sub
thanks
Last edited by joaquim; May 1st, 2008 at 02:50 PM.
i finish the function, but i only can one subimage. can anyone tell me why?
Code:
Option Explicit
Private Declare Function LoadCursorFromFile Lib "user32" Alias _
"LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Private Declare Function GetCursor Lib "user32" () As Long
Private Declare Function CopyIcon Lib "user32" (ByVal hcur As Long) As Long
Private mlngOldCursor As Long, lngNewCursor As Long
Private Declare Function DrawIconEx Lib "user32" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long
Const DI_MASK = &H1
Const DI_IMAGE = &H2
Const DI_NORMAL = DI_MASK Or DI_IMAGE
Public Sub AnimatedCursor(AniFilePath As String, picDestany As Variant)
Dim e As Long
Dim i As Long
If picDestany.Count > 1 Then
For e = 1 To picDestany.Count
Unload picDestany
Next e
End If
'Create a copy of the current cursor, 'for Windows NT compatibility
mlngOldCursor = CopyIcon(GetCursor())
'Check the passed string, if it contains
'a solid file path, then load the cursor
'from file. If not, add the App.Path, '*then* load cursor...
If InStr(1, AniFilePath, "\") Then
lngNewCursor = LoadCursorFromFile(AniFilePath)
Else
lngNewCursor = LoadCursorFromFile(App.Path & _
"\" & AniFilePath)
End If 'Activate the cursor
If i> 1 Then Load picDestany(i)
DrawIconEx picDestany(i).hdc, 0, 0, lngNewCursor, 0, 0, 0, 0, DI_NORMAL
i = i + 1
End Sub
i think that i don't have a cicle, but i don't know how to put it...
can anyone help me?
thanks
now i can simulate the animation, but i have one problem that i don't know resolve.
heres the function:
Code:
Public Sub AnimatedCursor(AniFilePath As String, index As Long, picDestany As Variant)
If InStr(1, AniFilePath, "\") Then
lngNewCursor = LoadCursorFromFile(AniFilePath)
Else
lngNewCursor = LoadCursorFromFile(App.Path & "\" & AniFilePath)
End If
DrawIconEx picDestany.hdc, 0, 0, lngNewCursor, 0, 0, index, 0, DI_NORMAL
End Sub
the function is working ok, but the problem is that i can't see how many subimages the file have... but the problem is: how can i see if the lngNewCursor varible is empy, null or something like that?
can anyone help me?
thanks
Option Explicit
Private Declare Function LoadCursorFromFile Lib "user32" Alias _
"LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Private Declare Function DrawIconEx Lib "user32" _
(ByVal hdc As Long, ByVal xLeft As Long, _
ByVal yTop As Long, ByVal hIcon As Long, _
ByVal cxWidth As Long, ByVal cyWidth As Long, _
ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, _
ByVal diFlags As Long) As Long
Private Declare Function DestroyIcon Lib "user32" (ByVal hIcon As Long) As Long
Const DI_NORMAL = &H3
Dim hCursor As Long
Code:
Private Sub cmdSelect_Click()
Timer1.Enabled = False
CommonDialog1.Filter = "Animated Cursors(*.ani)|*.ani"
CommonDialog1.ShowOpen
If hCursor > 0 Then
DestroyIcon hCursor
hCursor = 0
End If
hCursor = LoadCursorFromFile(CommonDialog1.FileName)
If hCursor > 0 Then Timer1.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
Timer1.Enabled = False
If hCursor > 0 Then
DestroyIcon hCursor
hCursor = 0
End If
Set Form1 = Nothing
End Sub
Private Sub Timer1_Timer()
Static i As Integer
AnimatedBox.Picture = Nothing
If DrawIconEx(AnimatedBox.hdc, 0, 0, hCursor, 32, 32, i, 0, DI_NORMAL) > 0 Then
i = i + 1
Else
i = 0: Timer1_Timer
End If
End Sub
Last edited by Edgemeal; May 4th, 2008 at 08:39 PM.
Reason: <<<<<<<<<< UPDATED CODE >>>>>>>>>>>>
The code in your zip file doesn't auto size the picture either, picture boxes only auto resize when a file is loaded or pasted in while in the IDE, not when drawn to.
honestly i don't know if they are -all animated cursors- 32X32 image size.
yes i can change the image size, but i wanted to know the original size...
but thanks for everything