如何编写托盘程序???

wenti2003 2003-05-11 08:33:17
UP
...全文
11 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
chinawzg 2003-05-11
用shell_notifyicon 函数 就可以实现的
http://www2.baidu.com/chains/chains.php?cn=cwwnet1

欢迎进入

http://www2.baidu.com/chains/chains.php?cn=cwwnet1
回复
踏平扶桑 2003-05-11
光盘中vb\COMMON\TOOLS\VB\UNSUPPRT\SYSTRAY有个systray.ocx,直接用就行了,很方便,不过功能不是很多
回复
griefforyou 2003-05-11
http://www.hongen.com/pc/program/apitutor/api0012/api01.htm
回复
LoveBH 2003-05-11
使用API函数Shell_NotifyIcon在窗体加载时创建托盘图标,在程序退出后删除托盘图标。使用API函数SetWindowLong和CallWindowProc接收托盘图标的消息并进行处理

代码如下
Option Explicit

Public LastState As Integer

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const SC_RESTORE = &HF120&
Private Const SC_SIZE = &HF000&

Private Sub Form_Load()
If WindowState = vbMinimized Then
LastState = vbNormal
Else
LastState = WindowState
End If
'调用添加托盘图标子程序
AddToTray Me, mnuTray
'调用在托盘图标上显示提示的子程序
SetTrayTip "托盘程序"
End Sub

' 使得快捷菜单的菜单项能随窗体的状态自动调整有效性
Private Sub Form_Resize()
Select Case WindowState
Case vbMinimized
mnuTrayMaximize.Enabled = True
mnuTrayMinimize.Enabled = False
mnuTrayMove.Enabled = False
mnuTrayRestore.Enabled = True
mnuTraySize.Enabled = False
Case vbMaximized
mnuTrayMaximize.Enabled = False
mnuTrayMinimize.Enabled = True
mnuTrayMove.Enabled = False
mnuTrayRestore.Enabled = True
mnuTraySize.Enabled = False
Case vbNormal
mnuTrayMaximize.Enabled = True
mnuTrayMinimize.Enabled = True
mnuTrayMove.Enabled = True
mnuTrayRestore.Enabled = False
mnuTraySize.Enabled = True
End Select

If WindowState <> vbMinimized Then
LastState = WindowState
End If
End Sub
'在窗体退出后,删除托盘中的图标
Private Sub Form_Unload(Cancel As Integer)
RemoveFromTray
End Sub

Private Sub mnuFileExit_Click()
Unload Me
End Sub
'单击快捷菜单中的Close菜单项
Private Sub mnuTrayClose_Click()
Unload Me
End Sub

'单击快捷菜单中的Maximize菜单项
Private Sub mnuTrayMaximize_Click()
WindowState = vbMaximized
End Sub

'单击快捷菜单中的Minimize菜单项
Private Sub mnuTrayMinimize_Click()
WindowState = vbMinimized
End Sub

'单击快捷菜单中的Move菜单项
Private Sub mnuTrayMove_Click()
SendMessage hwnd, WM_SYSCOMMAND, SC_MOVE, 0&
End Sub

'单击快捷菜单中的Restore菜单项
Private Sub mnuTrayRestore_Click()
SendMessage hwnd, WM_SYSCOMMAND, SC_RESTORE, 0&
End Sub

'单击快捷菜单中的Size菜单项
Private Sub mnuTraySize_Click()
SendMessage hwnd, WM_SYSCOMMAND, SC_SIZE, 0&
End Sub



欢迎光临电脑爱好者论坛 bbs.cfanclub.net
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7518

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2003-05-11 08:33
社区公告
暂无公告