VB6如何在托盘中写入应用程序图标
1.创建一个新的VB6项目,并将Form1的ShowInTaskBar属性设置为False。
2.菜单:工程-添加模块按“打开”添加一个新模块,命名为Module1,保存为Module1.bas
3.在模块1中编写以下代码:
选项显式
Public Const MAX _ TOOLTIP As Integer = 64
Public Const NIF _ ICON = & H2
Public Const NIF _ MESSAGE = & H1
Public Const NIF _ TIP = & H4
Public Const NIM _ ADD = & H0
Public Const NIM _ DELETE = & H2
Public Const WM _ MOUSEMOVE = & H200
Public Const WM _ lbutton down = & H201
Public Const
Public Const SW _ RESTORE = 9
Public Const SW _ HIDE = 0
公共nfIconData作为NOTIFYICONDATA
公共类型NOTIFYICONDATA
cbSize As Long
hWnd As Long
uID As Long
u flags As Long
uCallbackMessage As Long
hIcon As Long
SZ tip As String * MAX _ TOOLTIP
End Type
公共声明函数show window Lib " user 32 "(ByVal hWnd As Long,ByVal nCmdShow As Long)
公共声明函数Shell _ NotifyIcon Lib " Shell 32 . dll "别名" Shell _ NotifyIconA "(ByVal dw message As Long,LP data As NOTIFYICONDATA)Long
4.在Form1的Load事件中编写以下代码:
私有子窗体_Load()
下面,将程序放入系统托盘= = = = = = = = = = = = = = = = = = = = = = = =系统托盘begin
以nf图标数据
。hwnd = me.hw。uflags = nif _ icon或nif _ message或nif _ Tip
。ucallbackmessage = WM _ mousemove
。hicon = me.icon.handle
'定义鼠标移动到托盘时显示的提示
。szTip = App。Title+"(版本“& app.major &”。"& app.minor & "。"& app . revision & " " & vbnullchar
。cbsize = len(nf icon data)
End with
Call Shell _ NotifyIcon(NIM _ ADD,nfIconData)
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =系统托盘结束
Me。隐藏
结束Sub
5.在Form1的QueryUnload事件中编写以下代码:
private Sub Form _ QueryUnload(Cancel As Integer,unload mode As Integer)
Call Shell _ NotifyIcon(NIM _ DELETE,nfIconData)
End Sub
6.在Form1的MouseMove事件中编写以下代码:
private Sub Form _ MouseMove(Button As Integer,Shift As Integer,X As Single,As Single)
dimlmsg As Single
lmsg = X/screen . twipsperpixelx
select case lmsg
case WM _ lbuttonup
' msgbox "请用鼠标右键单击图标!"、vbInformation、“实时播报专家”
'点击左键显示窗体
ShowWindow Me.hWnd,SW_RESTORE
'下面两句话的目的是在窗口顶部显示窗口
' me . show
' me . set focus
' Case WM _ rbuttonup
popup menu MenuTray '如果你右击系统托盘图标,菜单菜单托盘
。
7.现在保存程序并运行它,看看这个项目的图标是否被添加到系统托盘中。点击此图标,会自动弹出Form1。
位律师回复
0条评论