vb托盘程序有毛病
这是主要代码:PublicDeclareFunctionShell_NotifyIconLib"shell32.dll"Alias"Shell_NotifyIconA"(...
这是主要代码:
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public 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 TheIco As NOTIFYICONDATA
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
With TheIco
.uFlags = 0
End With
X = Shell_NotifyIcon(Nim_DELETE, TheIco)
End Sub
Private Sub Form_Resize()
If WindowState = 1 Then
With TheIco
.uID = 0
.hwnd = Form1.hwnd 'f0rm1.HWnd为程序主窗体 de 句柄
.cbSize = Len(TheIco)
.uFlags = NIF_ICON
.uCallbackMessage = TRAY_CALLBACK
.hIcon = Form1.Icon.Handle 'form1.Icon.Handle指向主窗体 de 图标
.szTip = App.Title
End With
X = Shell_NotifyIcon(NIM_ADD, TheIco)
End If
End Sub 展开
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Public 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 TheIco As NOTIFYICONDATA
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
With TheIco
.uFlags = 0
End With
X = Shell_NotifyIcon(Nim_DELETE, TheIco)
End Sub
Private Sub Form_Resize()
If WindowState = 1 Then
With TheIco
.uID = 0
.hwnd = Form1.hwnd 'f0rm1.HWnd为程序主窗体 de 句柄
.cbSize = Len(TheIco)
.uFlags = NIF_ICON
.uCallbackMessage = TRAY_CALLBACK
.hIcon = Form1.Icon.Handle 'form1.Icon.Handle指向主窗体 de 图标
.szTip = App.Title
End With
X = Shell_NotifyIcon(NIM_ADD, TheIco)
End If
End Sub 展开
1个回答
展开全部
'我的代码是:
Begin VB.Menu fgkf
Caption = "文件"
Begin VB.Menu triyrt
Caption = "弹出"
End
Begin VB.Menu tjrt
Caption = "退出"
End
End
'模块
Option Explicit
Public Const MAX_TOOLTIP As Integer = 64
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_RBUTTONDBLCLK = &H206
Public Const SW_RESTORE = 9
Public Const SW_HIDE = 0
Public nfIconData As NOTIFYICONDATA
Public Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'窗体
Private Sub Form_Load()
With nfIconData '以下把程序放入System Tray===System Tray Begin
.hWnd = Me.hWnd
.uID = Me.Icon
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle
.szTip = App.Title + "( 版本 " & App.Major & "." & App.Minor & "." & App.Revision & " )" & vbNullChar
.cbSize = Len(nfIconData)
End With
Call Shell_NotifyIcon(NIM_ADD, nfIconData)
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim xc As Single
xc = X / Screen.TwipsPerPixelX
If Button And vbRightButton Then PopupMenu fgkf
Select Case xc
Case WM_LBUTTONUP
ShowWindow Me.hWnd, SW_RESTORE
Case WM_RBUTTONUP
PopupMenu fgkf
End Select
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
End Sub
Private Sub triyrt_Click()
MsgBox "我来了!", vbInformation, "跳出"
End Sub
Private Sub tjrt_Click()
End
End Sub
Begin VB.Menu fgkf
Caption = "文件"
Begin VB.Menu triyrt
Caption = "弹出"
End
Begin VB.Menu tjrt
Caption = "退出"
End
End
'模块
Option Explicit
Public Const MAX_TOOLTIP As Integer = 64
Public Const NIF_ICON = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIM_DELETE = &H2
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_RBUTTONDBLCLK = &H206
Public Const SW_RESTORE = 9
Public Const SW_HIDE = 0
Public nfIconData As NOTIFYICONDATA
Public Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * MAX_TOOLTIP
End Type
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
'窗体
Private Sub Form_Load()
With nfIconData '以下把程序放入System Tray===System Tray Begin
.hWnd = Me.hWnd
.uID = Me.Icon
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = Me.Icon.Handle
.szTip = App.Title + "( 版本 " & App.Major & "." & App.Minor & "." & App.Revision & " )" & vbNullChar
.cbSize = Len(nfIconData)
End With
Call Shell_NotifyIcon(NIM_ADD, nfIconData)
Me.Hide
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim xc As Single
xc = X / Screen.TwipsPerPixelX
If Button And vbRightButton Then PopupMenu fgkf
Select Case xc
Case WM_LBUTTONUP
ShowWindow Me.hWnd, SW_RESTORE
Case WM_RBUTTONUP
PopupMenu fgkf
End Select
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
End Sub
Private Sub triyrt_Click()
MsgBox "我来了!", vbInformation, "跳出"
End Sub
Private Sub tjrt_Click()
End
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询