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的。比如你直接从按钮移到窗体外。那按钮就不变了。 展开
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的。比如你直接从按钮移到窗体外。那按钮就不变了。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询