vb 最小化到托盘

即点击最小化按钮,他就像点击QQ最小化按钮一样跑托盘里去了,再在托盘里双击它它又出来了。。。。不要Copy,我也会,网上试的一个都不行。。。。... 即点击最小化按钮,他就像点击QQ最小化按钮一样跑托盘里去了,再在托盘里双击它它又出来了。。。。不要Copy,我也会,网上试的一个都不行。。。。 展开
 我来答
百度网友bdb9803
2012-06-07 · TA获得超过1.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:53%
帮助的人:1亿
展开全部
测试没问题,这些代码复制到模块中:

Option Explicit

'Win32 API declaration
Declare Function Shell_NotifyIcon Lib "shell32 " Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

' Constants used to detect clicking on the icon
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONUP = &H205

' Constants used to control the icon
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

' Used as the ID of the call back message
Public Const WM_MOUSEMOVE = &H200

' Used by Shell_NotifyIcon
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

'create variable of type NOTIFYICONDATA
Public TrayIcon As NOTIFYICONDATA

这些代码复制到窗体中:

Dim RR As Boolean

Private Sub Form_Load()

'centers form
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2

'sets cbSize to the Length of TrayIcon
TrayIcon.cbSize = Len(TrayIcon)
' Handle of the window used to handle messages - which is the this form
TrayIcon.hWnd = Me.hWnd
' ID code of the icon
TrayIcon.uId = vbNull
' Flags
TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' ID of the call back message
TrayIcon.ucallbackMessage = WM_MOUSEMOVE
' The icon - sets the icon that should be used
TrayIcon.hIcon = Me.Icon
' The Tooltip for the icon - sets the Tooltip that will be displayed
TrayIcon.szTip = App.Title & Chr$(0)

' Add icon to the tray by calling the Shell_NotifyIcon API
'NIM_ADD is a Constant - add icon to tray
Call Shell_NotifyIcon(NIM_ADD, TrayIcon)

' Don 't let application appear in the Windows task list
' App.TaskVisible = False

End Sub

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

Static Message As Long

'x is the current mouse location along the x-axis
Message = X / Screen.TwipsPerPixelX

If RR = False Then
RR = True
Select Case Message
' Left double click (This should bring up a dialog box)
Case WM_LBUTTONDBLCLK
Me.Show
' Right button up (This should bring up a menu)
Case WM_RBUTTONUP
' Me.PopupMenu mnuPopUp
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
'Remove icon for Tray
Call Shell_NotifyIcon(NIM_DELETE, TrayIcon)

End Sub

Private Sub Form_Resize()

If Me.WindowState = vbMinimized And Not RR Then Me.Hide

End Sub
更多追问追答
追问
模块和窗体各是什么。。。。我是个菜鸟额。。。。。。
追答
看图,在“工程1”上点右键,添加模块或窗体
AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
yichuha
2013-01-07 · TA获得超过256个赞
知道小有建树答主
回答量:212
采纳率:0%
帮助的人:147万
展开全部
推荐看一下新书“老兵新传:Visual Basic核心编程及通用模块开发”(清华大学出版社),书中代码可不加修改直接调用,像你这种问题调用书中通过模块的代码只需2句:
Dim WithEvents cSysTray As clsSysTray
cSysTray.AddSysTray Me.hwnd, Me.Icon, "这是Form1的托盘"

而且还可以像使用VB控件的事件编程那样,响应图标的事件,如在图标上单击、双击、单击右键、甚至鼠标移动:
Private Sub cSysTray_MouseDown(Button As Integer)
'Button=1,2,4分别表示按下了鼠标左键、右键、中间键!
If Button=1 then Me.PopupMenu mnuPopForm1
End Sub
Private Sub cSysTray_MouseUp(Button As Integer)
'鼠标抬起的事件
End Sub
Private Sub cSysTray_DblClick(Button As Integer)
'鼠标双击的事件

End Sub
Private Sub cSysTray_MouseMove()
'还支持鼠标移过图标的事件!
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式