Samuel Learning
联系
管理
文章分类
(203)
01 ASP/HTML(6)
02 Script/CSS(16)
03 C/C++
04 XML(4)
05 微软编程(26)
06 J2EE(60)
09 Linux(14)
10 Database(27)
11 报表打印
12 打包安装(1)
13 模式重构(2)
14 系统架构
15 敏捷开发(11)
16 案例分析(30)
17 Workflow(1)
18 配置管理(1)
19 项目管理
20 英语(4)
新闻分类
(52)
CXF学习
Hibernate学习(1)
iBatis学习(16)
Struts1学习(1)
Struts2学习(34)
.NET资源
adxmenu
C# Open Source
DNN Directory
M2Land
Windows Form FAQ
中国DNN
中国DNN联盟
Ajax
DoJo
GWT
JQuery
jquery autocomplete
jquery flexgrid
JQuery Form
jquery masked input
JQuery UI
jquery validation
Jquery 图表
jquery报表
jquery插件集合
Qooxdoo
Tibco GI
YUI
YUI-EXT
ZeroKode
Java开源
ABLE
Agile Tao
Ajax4JSF
Alfresco
AppFuse
Compiere
Equinox
Findbugs
Geronimo
Grails
Harmony
Hibernate论坛
JAG
Java开源大全
Java视线论坛
jBPM工作流
JSFTutorials
Nereide ERP
Ofbiz ERP
Opentaps ERP
operamasks
Petstore
Prototype.js
RIFE
Runa
SpringSide
Struts Menu
Sun Glassfish
Trails
YUI4JSF
满江红
Mobile
Sencha
WEB资源
DHTML中心
DHTML参考手册
DHTML文档
EclipsePlugin
Firebug
GRO Clinux
jMaki
JSTL文档
LoadIcon
Openlaszlo
Struts Menu 展示
Web Test Tools
WebCtrs
Webdeveloper
中国RIA开发者论坛
Workflow
E-Workflow
JBPM
OpenWFE
OSWorkflow
WFMC
Workflow Research
其他连接
confach
CPP
ejay
Giovanni
丹佛
交大e-learning
交大研究生院
可恶的猫
天天@blog
我的相册
阿飞
大牛人
32篇JBPM
David.Turing
HongSoft@业务集成
Joel
Koen Aers
Martinfowler
Raible Matt
Raible Wiki
Scott W.Ambler
Tom Baeyens
Uncle Bob
一个世界在等待
子在川上曰
小布老师
小明
差沙
徐昊
江南白衣
汪博士
汪小金
银狐999
开源软件
2Bizbox ERP
CompiereCRM&ERP
EGW
Vtiger CRM
webERP
敏捷
Canoo
Cruisecontrol
DBUnit
EL4Ant
Extreme Programming
Fit
Fitnesse
JFrog
Liquibase
Maven
MockObjects
Selenium
Squish
xpairtise
XPlanner
XProgramming
敏捷联盟
数据库
Oracle 中国
Oracle-ERP
Oracle在线社区
未归类
Aquarius Orm Studio
mambo建站系统
Oracle产品下载
远程同步管理工具Capivara
经典框架
Apache Shale
formdef-struts
FreeMarker 主页
JBoss Seam
JSF 中心
JSF 入门应用
JSF中国
MyFaces官方
Spring 社区
Spring专业网站
Spring中文论坛
Spring参考手册
Spring官方网站
strecks-struts
Struts1
Struts2
Struts-layout
StrutsWiKi
Tapestry WIKI
Tapestry 官方
Tapestry4开发指南
Tapestry中文文档
Webwork2文档
Wicket
网络教程
Laliluna
RoseIndia
Sang Shin
Visualbuilder
著名站点
Buildix
Dev2Dev
IBM dev中国
InfoQ
ITPub
Java Eye
Java Research
JavaRead
JavaWorldTW
Matrix
PHP100
PHPX
SpringSideWiKi
TheServerSide
TWPHP
中国工作流论坛
项目管理
管理人网
最新评论
View Post
我的VB托盘程序代码
Form1 的VB代码
Private
bIsQuit
As
Boolean
Private
Sub
Form_Load()
bIsQuit
=
False
End Sub
Private
Sub
Form_Unload(Cancel
As
Integer
)
If
Not
bIsQuit
Then
Dim
rc
As
Long
Dim
OwnerhWnd
As
Long
'
让窗体不可见
Me.Visible
=
False
'
从任务管理器列表中移除
OwnerhWnd
=
GetWindow(Me.HWnd, GW_OWNER)
rc
=
ShowWindow(OwnerhWnd, SW_HIDE)
Call
Icon_Add(Form1, Me.topmenu, Me.Timer1, Me.HWnd,
"
ICON Test
"
, Me.Icon,
0
)
Cancel
=
1
Else
Cancel
=
0
End
If
End Sub
Private
Sub
mnuQuit_Click()
bIsQuit
=
True
Call
Icon_Del(Me.HWnd,
0
)
'
删除通知栏图标
Unload Me
End Sub
Private
Sub
mnuShow_Click()
Call
Icon_Del(Me.HWnd,
0
)
'
删除通知栏图标
Me.Show
'
调出窗口
Me.WindowState
=
0
End Sub
Private
Sub
Timer1_Timer()
Call
Common.procesSD
End Sub
Common模块代码
'
Window消息处理函数,目的是: 窗口最小化到托盘时,程序自己处理消息
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
SendMessage Lib
"
user32
"
Alias
"
SendMessageA
"
(ByVal HWnd
As
Long
, ByVal wMsg
As
Long
, ByVal wParam
As
Long
, lParam
As
Any)
As
Long
'
点击X时,最小化到托盘
Public
Const
SW_HIDE
=
0
Public
Const
GW_OWNER
=
4
Declare
Function
GetWindow Lib
"
user32
"
(ByVal HWnd
As
Long
, ByVal wCmd
As
Long
)
As
Long
Declare
Function
ShowWindow Lib
"
user32
"
(ByVal HWnd
As
Long
, ByVal nCmdShow
As
Long
)
As
Long
'
添加、删除、更改托盘图标 Windows API
Declare
Function
Shell_NotifyIcon Lib
"
shell32.dll
"
Alias
"
Shell_NotifyIconA
"
(ByVal dwMessage
As
Long
, lpData
As
NOTIFYICONDATA)
As
Long
Public
Const
DefaultIconIndex
=
1
'
图标缺省索引
Public
Const
WM_LBUTTONDOWN
=
&
H201
'
按鼠标左键
Public
Const
WM_RBUTTONDOWN
=
&
H204
'
按鼠标右键
Public
Const
WM_LBUTTONDBLCLK
=
&
H203
'
双击左键
Public
Const
WM_USER
=
&
H400
Public
Const
TRAY_CALLBACK
=
(WM_USER
+
1001
&
)
Public
Const
GWL_WNDPROC
=
(
-
4
)
Public
Const
NIM_ADD
=
0
'
添加图标
Public
Const
NIM_MODIFY
=
1
'
修改图标
Public
Const
NIM_DELETE
=
2
'
删除图标
Public
Const
NIF_MESSAGE
=
1
'
message 有效
Public
Const
NIF_ICON
=
2
'
图标操作(添加、修改、删除)有效
Public
Const
NIF_TIP
=
4
'
ToolTip(提示)有效
Type NOTIFYICONDATA
cbSize
As
Long
'
需填入NOTIFYICONDATA数据结构的长度
HWnd
As
Long
'
设置成窗口的句柄
Uid
As
Long
'
为图标所设置的ID值
UFlags
As
Long
'
设置uCallbackMessage,hIcon,szTip是否有效
UCallbackMessage
As
Long
'
消息编号
hIcon
As
Long
'
显示在状态栏上的图标
SzTip
As
String
*
64
'
提示信息
End
Type
'
声明上述类型的对象
Private
IconVa
As
NOTIFYICONDATA
'
声明获取处理Windows 消息前的window句柄
Public
OldWindowProc
As
Long
'
判断单击,双击的两个标志
Private
bIsSingle
As
Boolean
Private
bIsDouble
As
Boolean
'
声明主窗体,右键菜单和时钟,这里的时钟是为了区分单双击左键,显得比较笨拙
Private
frmMain
As
Form
Private
topmenu
As
Menu
Private
timMain
As
Timer
'
函数定义
'
添加图标至通知栏
Public
Function
Icon_Add(frmParent
As
Form, mnuParent
As
Menu, timParent
As
Timer
, iHwnd
As
Long
, sTips
As
String
, hIcon
As
Long
, IconID
As
Long
)
As
Long
'
参数说明:iHwnd:窗口句柄,sTips:当鼠标移到通知栏图标上时显示的提示内容
'
hIcon:图标句柄,IconID:图标Id号
'
初始化控件成员
Set
frmMain
=
frmParent
Set
topmenu
=
mnuParent
Set
timMain
=
timParent
With
IconVa
.HWnd
=
iHwnd
.SzTip
=
sTips
+
Chr
$(
0
)
.hIcon
=
hIcon
.Uid
=
IconID
.UCallbackMessage
=
TRAY_CALLBACK
.cbSize
=
Len
(IconVa)
.UFlags
=
NIF_MESSAGE
Or
NIF_ICON
Or
NIF_TIP
End
With
'
获得让程序处理事件的权利
OldWindowProc
=
SetWindowLong(iHwnd, GWL_WNDPROC, AddressOf NewWindowProc)
'
初始化单双击的判别标志
bIsSingle
=
False
bIsDouble
=
False
'
初始化时钟
timMain.Enabled
=
True
timMain.Interval
=
500
Icon_Add
=
Shell_NotifyIcon(NIM_ADD, IconVa)
End Function
'
删除通知栏图标(参数说明同Icon_Add)
Function
Icon_Del(iHwnd
As
Long
, lIndex
As
Long
)
As
Long
Dim
IconVa
As
NOTIFYICONDATA
Dim
L
As
Long
With
IconVa
.HWnd
=
iHwnd
.Uid
=
lIndex
.cbSize
=
Len
(IconVa)
End
With
'
当图标从托盘删除后,关闭时钟,不在监视单双击事件
timMain.Enabled
=
True
'
让操作系统处理消息
SetWindowLong iHwnd, GWL_WNDPROC, OldWindowProc
Icon_Del
=
Shell_NotifyIcon(NIM_DELETE, IconVa)
End Function
'
修改通知栏图标(参数说明同Icon_Add)
Public
Function
Icon_Modify(iHwnd
As
Long
, sTips
As
String
, hIcon
As
Long
, IconID
As
Long
)
As
Long
Dim
IconVa
As
NOTIFYICONDATA
With
IconVa
.HWnd
=
iHwnd
.SzTip
=
sTips
+
Chr
$(
0
)
.hIcon
=
hIcon
.Uid
=
IconID
.UCallbackMessage
=
TRAY_CALLBACK
.cbSize
=
Len
(IconVa)
.UFlags
=
NIF_MESSAGE
Or
NIF_ICON
Or
NIF_TIP
End
With
Icon_Modify
=
Shell_NotifyIcon(NIM_MODIFY, IconVa)
End Function
'
程序处理Windows传递的消息
Public
Static
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
'
如果点击了右键
If
lParam
=
WM_RBUTTONDOWN
Then
'
则弹出右键菜单
frmMain.PopupMenu topmenu
Exit
Function
End
If
'
如果双击左键
If
lParam
=
WM_LBUTTONDBLCLK
Then
bIsDouble
=
True
bIsSingle
=
False
Exit
Function
End
If
'
如果点击了左键
If
lParam
=
WM_LBUTTONDOWN
Then
bIsSingle
=
True
bIsDouble
=
False
Exit
Function
End
If
End
If
'
如果是其他类型的消息则传递给原有默认的窗口函数
NewWindowProc
=
CallWindowProc(OldWindowProc, HWnd, Msg, wParam, lParam)
End Function
'
被时钟调用,来区分单击,还是双击,以及事件处理内容
Public
Sub
procesSD()
'
如果是双击,就恢复窗口,并把图标从托盘删除
If
bIsDouble
Then
Call
Icon_Del(frmMain.HWnd,
0
)
'
删除通知栏图标
frmMain.Show
'
调出窗口
frmMain.WindowState
=
0
frmMain.SetFocus
ElseIf
bIsSingle
Then
'
如果是单击,就弹出左键菜单
frmMain.PopupMenu topmenu
End
If
'
恢复单双击判断的标志
bIsSingle
=
False
bIsDouble
=
False
End Sub
posted on 2005-11-07 16:33
MingIsMe
阅读(2352)
评论(0)
编辑
收藏
所属分类:
05 微软编程