Results 1 to 12 of 12

Thread: [RESOLVED] Animated cursors

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Resolved [RESOLVED] Animated cursors

    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.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Animated cursors

    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Animated cursors

    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Animated cursors

    now i resolve the problem...
    if anyone want see animated cursors in a picturebox(or orther image control array), heres the project...
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [RESOLVED] Animated cursors

    Code removed, see #7
    Last edited by Edgemeal; May 4th, 2008 at 08:41 PM.

  6. #6

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] Animated cursors

    thanks for advice.. thank you
    VB6 2D Sprite control

    To live is difficult, but we do it.

  7. #7
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [RESOLVED] Animated cursors

    Code:
    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 >>>>>>>>>>>>

  8. #8

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] Animated cursors

    but now i have a question: i put the autosize property picturebox to true, but when the image is draw the size of picturebox isn't configured. why?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  9. #9
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [RESOLVED] Animated cursors

    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.

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] Animated cursors

    but can you help me how see the image size?
    thank you very much
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [RESOLVED] Animated cursors

    Not sure, I thought they were all 32x32 pixels?

    Update my code, see post #7 above, I set the drawicon code to draw em at 32,32 anyway, you can change that back to 0,0..
    Last edited by Edgemeal; May 4th, 2008 at 08:44 PM.

  12. #12

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] Animated cursors

    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
    VB6 2D Sprite control

    To live is difficult, but we do it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width