VBGood网站全文搜索 Google

首页 - 经验之谈 - 使用动画鼠标
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:8891, 日期:2001-04-19
Using Animated Cursors

Here注释:s a great way to add a little extra panache to your application ?use animated cursors!

When your program is busy whizzing and whirring, why not entertain the user by turning their cursor into a spinning globe, a wiggling starfish or a floating rocket?

You can, with this piece of code. Just run the StartAnimatedCursor method, passing the filename of an animated cursor file. When you want the animated cursor to stop and the old-style cursor to reappear, just call the RestoreCursor method.

Animated cursors can be found all over the place. Do a hard drive search for all files ending in .ANI ?you抣l probably a couple in Windows\Cursors.

If you don抰 already have it, you might also want to try installing 注释:Desktop Themes注释: (Windows 98 only) via the Control Panel, Add/Remove Programs, Windows Setup. That ships with around twenty or so animated cursors.

Note: If you only pass the StartAnimatedCursor method the animated cursor filename (ie, globe.ani) as opposed to its full path (ie, c:\windows\cursors\globe.ani), the code will attempt to find the .ANI file in the App.Path.


StartAnimatedCursor ("c:\windows\cursors\globe.ani")
MsgBox "Start long process here..."

注释: This code to be inserted into a module

Private Declare Function LoadCursorFromFile Lib "user32" Alias _
    "LoadCursorFromFileA" (ByVal lpFileName As String) As Long
Private Declare Function SetSystemCursor Lib "user32" _
    (ByVal hcur As Long, ByVal id As Long) As Long
Private Declare Function GetCursor Lib "user32" () As Long
Private Declare Function CopyIcon Lib "user32" (ByVal hcur As Long) As Long

Private Const OCR_NORMAL = 32512

Public lngOldCursor As Long, lngNewCursor As Long

Public Sub StartAnimatedCursor(AniFilePath As String)

    注释:Create a copy of the current cursor,
    注释:for Windows NT compatibility
    lngOldCursor = 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)
        lngNewCursor = LoadCursorFromFile(App.Path & _
            "\" & AniFilePath)
    End If
    注释:Activate the cursor
    SetSystemCursor lngNewCursor, OCR_NORMAL
End Sub

Public Sub RestoreLastCursor()

    注释:Restore last cursor
    SetSystemCursor lngOldCursor, OCR_NORMAL

End Sub