📄 将图标加入托盘.frm
字号:
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 885
ClientLeft = 60
ClientTop = 345
ClientWidth = 3885
ControlBox = 0 'False
Icon = "将图标加入托盘.frx":0000
LinkTopic = "Form2"
ScaleHeight = 885
ScaleWidth = 3885
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "取消图标"
Height = 315
Left = 2010
TabIndex = 1
Top = 210
Width = 1155
End
Begin VB.CommandButton Command1
Caption = "加入图标"
Height = 315
Left = 780
TabIndex = 0
Top = 210
Width = 1155
End
Begin VB.Image Image1
Height = 480
Left = 210
Picture = "将图标加入托盘.frx":0ECA
Top = 150
Visible = 0 'False
Width = 480
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' API 函数声明
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
' 字符常数说明
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
' 定义结构型变量
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
' 说明 TrayIcon 是结构型变量
Private TrayIcon As NOTIFYICONDATA
Private Sub Form_load()
' 窗体装入,设置图标及图标显示形式
TrayIcon.cbSize = Len(TrayIcon)
TrayIcon.hwnd = Me.hwnd
TrayIcon.uFlags = NIF_ICON Or NIF_TIP
TrayIcon.hIcon = Image1.Picture
TrayIcon.szTip = "Icon" & vbNullChar
End Sub
Private Sub Command1_Click()
' 在Windows任务栏中加入图标
Shell_NotifyIcon NIM_ADD, TrayIcon
End Sub
Private Sub Command2_Click()
' 从Windows任务栏中去掉图标
Shell_NotifyIcon NIM_DELETE, TrayIcon
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -