VB关于托盘处的右键菜单如何在鼠标移出时自动消失?或者单击其他的地方时消失?
我的代码已经是PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)Di...
我的代码已经是
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
msg = X / 15
If msg = WM_LBUTTONDBLCLK Then
Me.Show
Shell_NotifyIcon NIM_DELETE, nid
End If
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
Select Case lMsg
Case WM_RBUTTONUP
Form1.PopupMenu mnufile '这是我在托盘时右键之后弹出的菜单
End Select
End Sub
请问一下怎样才能在托盘处的右键菜单如何实现鼠标移出时自动消失?或者单击其他的地方时消失? 展开
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
msg = X / 15
If msg = WM_LBUTTONDBLCLK Then
Me.Show
Shell_NotifyIcon NIM_DELETE, nid
End If
Dim lMsg As Single
lMsg = X / Screen.TwipsPerPixelX
Select Case lMsg
Case WM_RBUTTONUP
Form1.PopupMenu mnufile '这是我在托盘时右键之后弹出的菜单
End Select
End Sub
请问一下怎样才能在托盘处的右键菜单如何实现鼠标移出时自动消失?或者单击其他的地方时消失? 展开
3个回答
展开全部
调用API函数,以下为一个例程,当鼠标移到按钮上时,按钮标题变为Welcome,移出时变为Hello
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Command1 'Change this to the name of the control
If Button = 0 Then
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
'Mouse pointer is outside button, so let other controls receive
'mouseevents too:
ReleaseCapture
Command1.Caption = "Hello"
' 放入鼠标离开的代码
Else
' Mouse pointer is over button, so we'll capture it, thus
' we'll receive mouse messages even if the mouse pointer is
' not over the button
SetCapture .hWnd
Command1.Caption = "Welcome"
' 放入鼠标进入的代码
End If
End If
End With
End Sub
Private Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
With Command1 'Change this to the name of the control
If Button = 0 Then
If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) Then
'Mouse pointer is outside button, so let other controls receive
'mouseevents too:
ReleaseCapture
Command1.Caption = "Hello"
' 放入鼠标离开的代码
Else
' Mouse pointer is over button, so we'll capture it, thus
' we'll receive mouse messages even if the mouse pointer is
' not over the button
SetCapture .hWnd
Command1.Caption = "Welcome"
' 放入鼠标进入的代码
End If
End If
End With
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询