Results 1 to 15 of 15

Thread: Animate mouse pointer

  1. #1

    Thread Starter
    Fanatic Member spud's Avatar
    Join Date
    Aug 2000
    Location
    Munster (Germany)
    Posts
    542

    Question

    Downloaded this programe that you create animated mouse icons can anyone tell me how to asign it to a click event?

    Cheers


    Spud

  2. #2
    Guest
    What do you mean by assigning it to a click event?

  3. #3
    Guest
    If you mean displaying it when a button is clicked, you can use the following code.

    Insert code in a Form with a CommonDialog and a CommandButton
    Code:
    Private Declare Function LoadCursorFromFile Lib "User32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
    Private Declare Function SetClassLong Lib "User32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Const GCL_HCURSOR = (-12)
    Dim prevCur As Long
    Dim MyCursor As Long
    
    Private Sub Command1_Click()
    
        Dim OpenFile As String
        CommonDialog1.Filter = "Animated Cursors (*.ani)|*.ani"
        CommonDialog1.ShowOpen
        
        OpenFile = CommonDialog1.filename
        
        MyCursor = LoadCursorFromFile(OpenFile)
        prevCur = SetClassLong(Me.hwnd, GCL_HCURSOR, MyCursor)
    
        
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        prevCur = SetClassLong(Me.hwnd, GCL_HCURSOR, hOldCursor)
    End Sub

  4. #4

    Thread Starter
    Fanatic Member spud's Avatar
    Join Date
    Aug 2000
    Location
    Munster (Germany)
    Posts
    542

    Smile

    Megatron I think Im doing somthing wrong with this part of the code can you help?

    CommonDialog1.Filter = ("C:\My Documents\gdsm.ani")


    Thanks again

    Spud

  5. #5
    Guest
    The Filter is the type of files you want to open. Just leave it at CommonDialog1.Filter = "Animated Cursors (*.ani)|*.ani" and it should work fine.

    If you do not want to load it from the CommonDialog, then
    use this line instead. MyCursor = LoadCursorFromFile("C:\My Documents\gdsm.ani")

  6. #6

    Thread Starter
    Fanatic Member spud's Avatar
    Join Date
    Aug 2000
    Location
    Munster (Germany)
    Posts
    542

    Smile

    Thanks again Megatron thats it sorted now.


    Cheers!

    Spud



  7. #7
    Junior Member taximania's Avatar
    Join Date
    Sep 2001
    Location
    Derbyshire, England
    Posts
    28

    On mouseover

    How would I alter the code so that an animated cursor is displayed when hovering over command1 only
    Help, is always appreciated.

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    This can do both Cursors and Icons:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    4.    Command1.DragIcon = LoadPicture("C:\Program Files\Microsoft Visual Studio\Vfp98\FFC\Graphics\H_point.cur")
    5.    Command1.Drag vbBeginDrag
    6. End Sub
    7.  
    8. Private Sub Command1_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
    9.    If State = vbLeave Then
    10.       Command1.Drag vbEndDrag
    11.    End If
    12. End Sub

  9. #9
    Junior Member taximania's Avatar
    Join Date
    Sep 2001
    Location
    Derbyshire, England
    Posts
    28

    Thumbs down That gives an Invalid Picture error

    Doesn't that code do the same as Properties-Form1 Icon
    It doesn't appear to work with .ani files.
    Help, is always appreciated.

  10. #10
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Nope, it won't do .ani (Only Cursors and Icons)

    I posted it incase u were just after Cursors

  11. #11
    Junior Member taximania's Avatar
    Join Date
    Sep 2001
    Location
    Derbyshire, England
    Posts
    28

    Smile The question still stands

    How do I display an animated (.ani) cursor over such as a command1 button ? plz
    Help, is always appreciated.

  12. #12
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Try:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function LoadCursorFromFile Lib "User32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
    4. Private Declare Function SetClassLong Lib "User32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    5. Private Const GCL_HCURSOR = (-12)
    6. Dim prevCur As Long
    7. Dim MyCursor As Long
    8.  
    9. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    10.     MyCursor = LoadCursorFromFile("C:\Windows\Cursors\Hourglas.ani")
    11.     prevCur = SetClassLong(Command1.hwnd, GCL_HCURSOR, MyCursor)
    12.  
    13. End Sub
    14.  
    15. Private Sub Form_Unload(Cancel As Integer)
    16.     prevCur = SetClassLong(Me.hwnd, GCL_HCURSOR, hOldCursor)
    17. End Sub

    The only problem at the moment is the error on unload.
    I'm trying to fix it. The Cursor remains the HourGalss! (until u
    close VB)

  13. #13
    Junior Member taximania's Avatar
    Join Date
    Sep 2001
    Location
    Derbyshire, England
    Posts
    28

    Smile Cheers Bruce

    I removed the unload form bit of the code and it works perfect.
    Thanks.
    Help, is always appreciated.

  14. #14
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Good job

    Seems to work well!

    Does anyone see a problem with it?
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function LoadCursorFromFile Lib "User32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
    4. Private Declare Function SetClassLong Lib "User32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    5. Private Const GCL_HCURSOR = (-12)
    6. Dim prevCur As Long
    7. Dim MyCursor As Long
    8.  
    9. Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    10.     MyCursor = LoadCursorFromFile("C:\Windows\Cursors\Hourglas.ani")
    11.     prevCur = SetClassLong(Command1.hwnd, GCL_HCURSOR, MyCursor)
    12. End Sub

  15. #15
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    You were trying to set it to hOldCursor in form uload..which is never defined?
    And I, for one, welcome our new insect overlords. I'd like to remind them as a trusted TV personality, I can be helpful in rounding up others to toil in their underground sugar caves.

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