vb编的一个小程序,如何让他在点击右上角关闭按钮(就是那个叉号)时,在托盘 里继续运行?

 我来答
syly000
2011-02-13 · 超过15用户采纳过TA的回答
知道答主
回答量:64
采纳率:0%
帮助的人:17.5万
展开全部
VB6:
你可以在工程里多建一个窗体,操作的菜单写在这里,不显示9 OK了
当你要的窗体关闭后 再+载托盘

VB.NET里直接9有Closing和Closed事件

以下9是托盘:
Dim OldWindowProc As Long
Dim TheForm As Form
Dim TheMenu As Menu

Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetLayeredWindowAttributes Lib "user32" _
(ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, _
ByVal dwFlags As Long) As Long

Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

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 TheData As NOTIFYICONDATA

Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = (&H400 + 1001&) Then
If lParam = &H205 Then
FormM.SetFocus
TheForm.PopupMenu TheMenu
Exit Function
End If
End If
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
End Function

Public Sub AddToTray(frm As Form, mnu As Menu)
Set TheForm = frm
Set TheMenu = mnu
OldWindowProc = SetWindowLong(frm.hwnd, (-4), AddressOf NewWindowProc)
With TheData
.Uid = 0
.hwnd = frm.hwnd
.cbSize = Len(TheData)
.HIcon = frm.Icon.Handle
.UFlags = 2
.UCallbackMessage = (&H400 + 1001&)
.UFlags = .UFlags Or 1
.cbSize = Len(TheData)
End With
Shell_NotifyIcon 0, TheData
End Sub

Public Sub RemoveFromTray()
With TheData
.UFlags = 0
End With
Shell_NotifyIcon 2, TheData
SetWindowLong TheForm.hwnd, (-4), OldWindowProc
End Sub

Public Sub SetTrayTip(tip As String)
With TheData
.SzTip = tip & vbNullChar
.UFlags = 4
End With
Shell_NotifyIcon 1, TheData
End Sub
knowdetail
2011-02-13 · TA获得超过156个赞
知道小有建树答主
回答量:342
采纳率:0%
帮助的人:265万
展开全部
上网查查,有很多的托盘控件. 在FORM_QUERYUNLOAD中写代码,最小到托盘就行了.
可以HI我.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式