VB 定时弹窗
发布网友
发布时间:2022-09-04 03:42
我来回答
共2个回答
热心网友
时间:2024-11-16 07:54
添加两个窗体,一个Form1、一个Form2
Form1上添加一个Picture、一个Timer、一个菜单(名为Menu1)及一个子菜单(名为mnuEnd)
以下为完成代码:
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
'以上为托盘
Dim ttt As NOTIFYICONDATA
Private Sub Form_Load()
Picture1.Picture = Me.Icon
ttt.cbSize = Len(ttt)
ttt.hWnd = Picture1.hWnd
ttt.uId = 1&
ttt.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
ttt.ucallbackMessage = WM_MOUSEMOVE
ttt.hIcon = Me.Picture1.Picture
ttt.szTip = Replace(Me.Caption, vbCrLf, "") & Chr$(0)
Shell_NotifyIcon NIM_ADD, ttt
Me.Visible = False
Menu1.Visible = False
Timer1.Interval = 60000'如果想测试程序效果,将此值设小点
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = 1
Me.Visible = False
End Sub
Private Sub mnuEnd_Click()
Shell_NotifyIcon NIM_DELETE, ttt
End
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
On Error Resume Next
Select Case Hex(X)
Case "1E3C", "1E0F" '右键按下1E3C、左键按下1E0F
If Menu1.Visible Then
Menu1.Visible = False
Else
PopupMenu Menu1
End If
Case "1E2D" '双击左键
Me.Visible = Not Me.Visible
End Select
End Sub
Private Sub Timer1_Timer()
Static a As Integer
a = a + 1
If a Mod 60 > 0 Then Exit Sub
Form2.Left = Screen.Width - Form2.Width
Form2.Top = Screen.Height - Form2.Height
Form2.Show
a = 0
End Sub
热心网友
时间:2024-11-16 07:55
搜索“托盘”