VB 鼠标移出Imagelist控件-更换图片

我先把代码发一下。PrivateDeclareFunctionReleaseCaptureLib"user32"()AsLongPrivateDeclareFunctio... 我先把代码发一下。
Private Declare Function ReleaseCapture Lib "user32" () As Long

Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Declare Function SetWindowPos& Lib "user32" (ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)

Private Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1

Private Const WM_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2

Dim MaxWindow As Boolean, myHeight As Integer, myWidth As Integer
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long

Private Sub Form_Load()
Dim rtn As Long
rtn = GetWindowLong(hWnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hWnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hWnd, 0, 220, LWA_ALPHA
Dim myval
myval = SetWindowPos(Form1.hWnd, -1, 0, 0, 0, 0, 3)
Image1.Picture = LoadPicture(App.Path & "/skin/" & "Min_Normal.bmp")
'Image2.Picture = LoadPicture(App.Path & "/skin/" & "Min_Normal.bmp")
'Image3.Picture = LoadPicture(App.Path & "/skin/" & "Skin_Normal.bmp")
'Image4.Picture = LoadPicture(App.Path & "/skin/" & "Close_Normal.bmp")
End Sub

Private Sub form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
ReleaseCapture
SendMessage hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

Private Sub Image1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Image1.Picture = LoadPicture(App.Path & "/skin/" & "Min_move.bmp")
Dim mouseexit As Boolean
mouseexit = (0 <= x) And (x <= Image1.Width) And (0 <= y) And (y <= Image1.Height)
If mouseexit Then
SetCapture Image1.hWnd
Else
ReleaseCapture
Image1.Picture = LoadPicture(App.Path & "/skin/" & "Min_normal.bmp")
End If
End Sub

实现的效果就是载入时。image图片是normal.bmp正常。当鼠标移到imagelist控件的时候。变成move.bmp都是假设。当鼠标从image中移出后。又是normal.bmp。。我不知道这里哪里错了。就是实现不了。移过去变了。移出。还是一样。。。请高手帮忙。谢谢
ok。已解决。是imagelist没有hwnd属性。换成picture控件就可以了。。低楼的form和按钮的判断会有bug的。比如你直接从按钮移到窗体外。那按钮就不变了。
展开
 我来答
joforn
2008-04-06 · TA获得超过112个赞
知道小有建树答主
回答量:169
采纳率:0%
帮助的人:237万
展开全部
VB中的控件本身事件不包含鼠标移出事件,如果一定要实现这个功能则要用到HOOK,但VB中的Image控件没有hWnd这个属性,所以变得更麻烦了。你可以把Image控件用PictureBox控件代替,然后HOOK就行了。但这样做比较麻烦。
折中的方式是在Form的MouseMove事件中处理图片更换(前提是Iamge是放在Form上或是在Iamge的容器控件的MouseMove中处理)。
lzh741206
2008-04-06 · TA获得超过1192个赞
知道大有可为答主
回答量:1929
采纳率:100%
帮助的人:2800万
展开全部
在From的MouseMove事件里也要判断吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式