VB关于托盘处的右键菜单如何在鼠标移出时自动消失?或者单击其他的地方时消失?

来源:百度知道 编辑:UC知道 时间:2024/05/15 19:49:00
我的代码已经是
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

请问一下怎样才能在托盘处的右键菜单如何实现鼠标移出时自动消失?或者单击其他的地方时消失?

调用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
SetCaptu