如何让窗体启动后可以缩在右下的系统托盘中?

nirvana_hg 2003-12-11 11:07:10
就是变成一个小图标缩在右下方的系统托盘中,请写一个**完整可用**的方法。
谢谢!!!
附:本人不是用VB的,现用现问,因此下面三种回答不能给分,请原谅
1、只给思路的
2、让我去看基础书或查API的
3、写出方法不可用的

我一直在线,代码成功即结帖
...全文
28 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
jone999 2003-12-11
  • 打赏
  • 举报
回复
奇怪结贴了怎么还可以回复?~~~Why?
jone999 2003-12-11
  • 打赏
  • 举报
回复
no
hxy2003 2003-12-11
  • 打赏
  • 举报
回复
到网上找找许多这样的代码
jone999 2003-12-11
  • 打赏
  • 举报
回复
在VB中使用如下,参考:
Public OldWindowProc As Long
Public TheForm As Form
Public 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 Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

Public Const WM_USER = &H400
Public Const WM_LBUTTONUP = &H202
Public Const WM_MBUTTONUP = &H208
Public Const WM_RBUTTONUP = &H205
Public Const TRAY_CALLBACK = (WM_USER + 1001&)
Public Const GWL_WNDPROC = (-4)
Public Const GWL_USERDATA = (-21)
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const NIM_ADD = &H0
Public Const NIF_MESSAGE = &H1
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2

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

Private TheData As NOTIFYICONDATA
' *********************************************
' The replacement window proc.
' *********************************************
Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = TRAY_CALLBACK Then
' The user clicked on the tray icon.
' Look for click events.
If lParam = WM_LBUTTONUP Then
' On left click, show the form.
If TheForm.WindowState = vbMinimized Then _
TheForm.WindowState = TheForm.LastState
TheForm.SetFocus
Exit Function
End If
If lParam = WM_RBUTTONUP Then
' On right click, show the menu.
TheForm.PopupMenu TheMenu
Exit Function
End If
End If

' Send other messages to the original
' window proc.
NewWindowProc = CallWindowProc( _
OldWindowProc, hwnd, Msg, _
wParam, lParam)
End Function
' *********************************************
' Add the form's icon to the tray.
' *********************************************
Public Sub AddToTray(frm As Form, mnu As Menu)
' ShowInTaskbar must be set to False at
' design time because it is read-only at
' run time.

' Save the form and menu for later use.
Set TheForm = frm
Set TheMenu = mnu

' Install the new WindowProc.
OldWindowProc = SetWindowLong(frm.hwnd, _
GWL_WNDPROC, AddressOf NewWindowProc)

' Install the form's icon in the tray.
With TheData
.uID = 0
.hwnd = frm.hwnd
.cbSize = Len(TheData)
.hIcon = frm.Icon.Handle
.uFlags = NIF_ICON
.uCallbackMessage = TRAY_CALLBACK
.uFlags = .uFlags Or NIF_MESSAGE
.cbSize = Len(TheData)
End With
Shell_NotifyIcon NIM_ADD, TheData
End Sub
' *********************************************
' Remove the icon from the system tray.
' *********************************************
Public Sub RemoveFromTray()
' Remove the icon from the tray.
With TheData
.uFlags = 0
End With
Shell_NotifyIcon NIM_DELETE, TheData

' Restore the original window proc.
SetWindowLong TheForm.hwnd, GWL_WNDPROC, _
OldWindowProc
End Sub
' *********************************************
' Set a new tray tip.
' *********************************************
Public Sub SetTrayTip(tip As String)
With TheData
.szTip = tip & vbNullChar
.uFlags = NIF_TIP
End With
Shell_NotifyIcon NIM_MODIFY, TheData
End Sub
' *********************************************
' Set a new tray icon.
' *********************************************
Public Sub SetTrayIcon(pic As Picture)
' Do nothing if the picture is not an icon.
If pic.Type <> vbPicTypeIcon Then Exit Sub

' Update the tray icon.
With TheData
.hIcon = pic.Handle
.uFlags = NIF_ICON
End With
Shell_NotifyIcon NIM_MODIFY, TheData
End Sub
nirvana_hg 2003-12-11
  • 打赏
  • 举报
回复
先结帖,难得碰上热心的好人。
nirvana_hg 2003-12-11
  • 打赏
  • 举报
回复
太长了,等我慢慢分析……-_!
zyl910 2003-12-11
  • 打赏
  • 举报
回复
http://www.fantasiasoft.net/Zyl910/SysTray1.zip
系统托盘编程大全 For VB
作者:zyl910

这个程序包括了所有的托盘程序设计技巧:
1.托盘菜单可以消去
2.Explorer非法操作后能自动恢复图标
3.气泡提示
4.托盘图标的隐藏
SoHo_Andy 2003-12-11
  • 打赏
  • 举报
回复
已经发送了,请接收
zyl910 2003-12-11
  • 打赏
  • 举报
回复
看FAQ:
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=197
nirvana_hg 2003-12-11
  • 打赏
  • 举报
回复
谢谢,kasurain@hotmail.com
SoHo_Andy 2003-12-11
  • 打赏
  • 举报
回复
呵呵,留个邮箱,发个例子给你

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧