让VB5支持动画光标

 

    在VB5中,鼠标指针通常是由窗体或其他控件的MouseIcon 属性来设置,但MouseIcon属性不支持彩色光标(*.cur)和动画光标(*.ani)。因此,要想在程序中使用上述光标,就不得不借助Windows 中的API 函数Set—ClassLong ,该函数的功能是设置和修改窗体中某些属性的值,并返回该属性原来的值。
  其格式如下:SetClassLong hwnd ,nIndex,dwNewLong其中:hwnd 代表要设置光标的窗体或控件的句柄;nIndex 设置为常数-12,表示设置光标;dwNewLong 代表新的光标文件,可由另一API 函数LoadCursorFromFile 获得。
  设置光标后,在程序结束时,应将光标复原,因此可以将SetClassLong 返回的原始光标存到变量中,再在窗体的Unload 事件中将其还原。具体步骤如下:创建新工程
将如下代码加入到Form1的“通用”|“声明”中:
Option Explicit
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
Di mNewCur As Long
Di mOldCur As Long
创建Lo ad 事件
将如下代码加入到Form1的Load 事件中:
Private Sub Form_Load()
NewCur =LoadCursorFromFile("C:\
Windows\abcde .ani")
OldCur =SetClassLong(hwnd ,-12,
NewCur)End Sub
   创建U nlo ad 事件
将如下代码加入到Form1的Unload 事
件中:Private Sub Form_Unload(Cancel As Integer)
Set—
ClassLong hwnd ,
-12,OldCur
End Sub
(浙江省温岭市太平镇兰田新村3—2号陈小勇317500)

(上一页)---(下一页)