vb中怎么最小化系统托盘

vb中怎么最小化系统托盘,第1张

首先添加一个模块,写入代码,代码我已经准备好了

然再给Form窗体添加代码

模块

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

From窗体Private Sub Command1_Click()

With nfIconData

.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_QueryUnload(Cancel As Integer, UnloadMode As Integer)

Call Shell_NotifyIcon(NIM_DELETE, nfIconData)

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

Dim lMsg As Single

lMsg = X / Screen.TwipsPerPixelX

Select Case lMsg

Case WM_LBUTTONUP

ShowWindow Me.hWnd, SW_RESTORE

End Select

End Sub

日上龙脊10级2009-06-12vb系统托盘程序图标需要添加一个按钮command1 Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long Private nfIconData As NOTIFYICONDATA Option Explicit Const MAX_TOOLTIP As Integer = 64 Const NIF_ICON = &H2 Const NIF_MESSAGE = &H1 Const NIF_TIP = &H4 Const NIM_ADD = &H0 Const NIM_DELETE = &H2 Const WM_MOUSEMOVE = &H200 Const WM_LBUTTONDOWN = &H201 Const WM_LBUTTONUP = &H202 Const WM_LBUTTONDBLCLK = &H203 Const WM_RBUTTONDOWN = &H204 Const WM_RBUTTONUP = &H205 Const WM_RBUTTONDBLCLK = &H206 Const SW_RESTORE = 9 Const SW_HIDE = 0 Private 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 Private Sub Command1_Click() nfIconData.hwnd = Me.hwnd nfIconData.uID = Me.Icon nfIconData.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP nfIconData.uCallbackMessage = WM_MOUSEMOVE nfIconData.hIcon = Me.Icon.Handle nfIconData.szTip = "显示" &vbNullChar nfIconData.cbSize = Len(nfIconData) Call Shell_NotifyIcon(NIM_ADD, nfIconData) ShowWindow Me.hwnd, SW_HIDE End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim lMsg As Single lMsg = X / Screen.TwipsPerPixelX If lMsg = WM_RBUTTONUP Or lMsg = WM_LBUTTONUP Then Call Shell_NotifyIcon(NIM_DELETE, nfIconData) '退出图标 Me.Show End If追问:晕你发的都是网上发过的,我在说一遍我只要可用的源文件,直接拿去测试,不是要你发的代码。我要源文件 源文件 源文件 源文件 源文件啊!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7834430.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存