VB按下命令按钮就让程序最小化到托盘
1个回答
推荐于2017-09-30
展开全部
'测试没问题,这些代码复制到模块中:
Declare Function Shell_NotifyIcon Lib "shell32 " Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONUP = &H205
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIF_MESSAGE = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_MOUSEMOVE = &H200
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
Public TrayIcon As NOTIFYICONDATA
'----------------------------------------------------------------------------
'这些代码复制到窗体中:
Dim RR As Boolean
Private Sub Form_Load()
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
TrayIcon.cbSize = Len(TrayIcon)
TrayIcon.hWnd = Me.hWnd
TrayIcon.uId = vbNull
TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
TrayIcon.ucallbackMessage = WM_MOUSEMOVE
TrayIcon.hIcon = Me.Icon
TrayIcon.szTip = App.Title & Chr$(0)
Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static Message As Long
Message = X / Screen.TwipsPerPixelX
If RR = False Then
RR = True
Select Case Message
Case WM_LBUTTONDBLCLK
Me.Show
Case WM_RBUTTONUP
End Select
RR = False
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
TrayIcon.cbSize = Len(TrayIcon)
TrayIcon.hWnd = Me.hWnd
TrayIcon.uId = vbNull
Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)
End Sub
Private Sub Form_Resize()
If Me.WindowState = vbMinimized And Not RR Then Me.Hide
End Sub
Private Sub Command1_Click()
Me.WindowState = vbMinimized
End Sub
更多追问追答
追问
可是我有多个窗体,我想让整个工程的窗体都最小化到托盘,然后按托盘中的图标后,跳出主窗体Main
追答
'回答受字数限制,根据上面代码,我大概讲一下。
'1、模块代码不变。
'2、窗体代码Private Sub Command1_Click()过程除外,其它代码全部放到Main主窗体中,并把各个事件代码的Form改为MDIForm 如Private Sub Form_Load()应改为Private Sub MDIForm_Load()
'3、在各个窗体的最小化按纽事件中添加下面事件。
Private Sub Command1_Click()
MDIForm1.WindowState = vbMinimized
End Sub
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询