vb如何实现:经过图片时,指针变成手指?
3个回答
展开全部
vb中鼠标指针样式没有手指型的鼠标,但是可以调用系统API来实现
你可以使用API函数
SetCursor和LoadCursor实现
'新建一个标准模块,定义函数
Public Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As String) As Long
'常量
Public Const IDC_HAND = "#32649"
'定义一个手指型鼠标保存的变量
Public hHandCursor As Long
在Form_Load事件中
hHandCursor = LoadCursor(0, IDC_HAND)
在图片的mousemove事件中
SetCursor hHandCursor
你可以使用API函数
SetCursor和LoadCursor实现
'新建一个标准模块,定义函数
Public Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Public Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As String) As Long
'常量
Public Const IDC_HAND = "#32649"
'定义一个手指型鼠标保存的变量
Public hHandCursor As Long
在Form_Load事件中
hHandCursor = LoadCursor(0, IDC_HAND)
在图片的mousemove事件中
SetCursor hHandCursor
展开全部
楼上的代码每次移动鼠标都触发事件,会比较耗费资源,而且在图片上按下鼠标时,指针会恢复成箭头,造成闪烁的感觉,下面的代码也是利用MouseIcon属性设置,但不需要手形的cur或ico文件。
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As String) As Long
Private Const IDC_HAND = "#32649"
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Sub Form_Load()
Dim hHandCursor As Long
hHandCursor = LoadCursor(0, IDC_HAND)
Picture1.MouseIcon = CreatePicture(hHandCursor)
Picture1.MousePointer = 99
End Sub
'从hCursor句柄创建icon图像
Private Function CreatePicture(ByVal hCursor As Long) As StdPicture
Dim pic As PicBmp
Dim IID_IDispatch As GUID
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
With pic
.Size = Len(pic)
.Type = vbPicTypeIcon
.hBmp = hCursor
.hPal = 0
End With
OleCreatePictureIndirect pic, IID_IDispatch, 1, CreatePicture
End Function
Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As String) As Long
Private Const IDC_HAND = "#32649"
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Sub Form_Load()
Dim hHandCursor As Long
hHandCursor = LoadCursor(0, IDC_HAND)
Picture1.MouseIcon = CreatePicture(hHandCursor)
Picture1.MousePointer = 99
End Sub
'从hCursor句柄创建icon图像
Private Function CreatePicture(ByVal hCursor As Long) As StdPicture
Dim pic As PicBmp
Dim IID_IDispatch As GUID
With IID_IDispatch
.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46
End With
With pic
.Size = Len(pic)
.Type = vbPicTypeIcon
.hBmp = hCursor
.hPal = 0
End With
OleCreatePictureIndirect pic, IID_IDispatch, 1, CreatePicture
End Function
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在mouseicon选择手型图标就可以
追问
这样不方便。变成手型图标时,会移位(即手型图标不是指向原来位置)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询