Solved

Animated cursor

Posted on 2004-04-02
6
1,220 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
matchUp  challenge 9 110
delphi parse string to params 3 123
API Soap Calls 4 117
Problem to error 4 60
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 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