Solved

Animated cursor

Posted on 2004-04-02
6
1,204 Views
Last Modified: 2013-11-19
Hello Experts.
I am using VB6.
I would like to make the mouse pointer animated and/or make an animated picture on a form.
I know how to do it in Windows,but I would like to do it in the program when I want it.
Is there a way to do it ?
Thanks
0
Comment
Question by:HESUS
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:Tommy Kinard
ID: 10741009
Hi HESUS,

The code below will show and animated mouse pointer. This one is loaded from a file on the hard drive.

Private Sub CmdAnimateCursor()
    Dim filename As String
    filename = "C:\directory" & "\animatedfile.ani"
    new_cursor = LoadCursorFromFile(filename)
    old_cursor = GetCursor()
    old_cursor = CopyCursor(old_cursor)
    SetSystemCursor new_cursor, OCR_NORMAL
End Sub

Private Sub CmdNormalCursor()
    SetSystemCursor old_cursor, OCR_NORMAL
    old_cursor = 0
End Sub
Private Sub Form_Load()
    SetSystemCursor 0, OCR_NORMAL
End Sub

HTH
dragontooth

0
 
LVL 1

Expert Comment

by:NO_CARRIER
ID: 10745702
it depends.. when do you want the cursor to animate?.. all the time?.. when loading?... on hover?
0
 

Author Comment

by:HESUS
ID: 10791461
To dragontooth.
I tried the code you sent me,and I get the following error message:
"Can't find DLL entry point CopyCursor in user32".
I am using VB6 and I tried to copy another user32 from another machine,but with no luck.
Any idea?

To NO CARRIER, I want to change the cursor in the middle of the program for a while,and then change it back to the default.

Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Accepted Solution

by:
NO_CARRIER earned 50 total points
ID: 10804828
okay... this is what you need:

Declare Function LoadCursorFromFile Lib "user32" Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Const GCL_HCURSOR = (-12)
Dim sCursorFile As String
Dim hCursor As Long
Dim hOldCursor As Long
Dim lReturn As Long

sCursorFile = "d:\winnt\cursors\globe.ani" 'load animated cursor

' Set the animated cursor
hCursor = LoadCursorFromFile(sCursorFile)
hOldCursor = SetClassLong(Form1.hwnd, GCL_HCURSOR, hCursor)

' Restore the cursor
lReturn = SetClassLong(Form1.hWnd, GCL_HCURSOR, hOldCursor)
0
 
LVL 1

Expert Comment

by:NO_CARRIER
ID: 10804836
also.. if the cursor animation is while something is loading... (similar to an hourglass).. it's always a good idea to disable the user from interacting with the form.

'during animated cursor
Form1.Enabled=False

'restore default cursor
'Form1.Enabeld=True


+++ath0
NO CARRIER
0
 

Author Comment

by:HESUS
ID: 10857606
To NO CARRIER many thanks.It is working.
There are two problems though:
1. If I move the cursor to one of the controls on the form,the animation disapears.If I disable the form then the animation is not working.
2.When I try to restore the default cursor,it will not restore until I move the cursor to one of the controls on the form.

Otherwise it works fine.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now