您的批评和鼓励都是我把编程无限办好的动力! 您编程时遇到困难,或遇到不顺心的事想发发牢骚尽管到这里来吧! 虽然本网力求全面,但也不能包罗万象,这些我筛选出的优秀网站连接就是对本站最好的补充! 学习编程当然也离不开书本了,这里收集大量编程书籍! 编程无限之源码超市,这里收集的代码令你意想不到的全面! 欢迎光临编程网校,这里专门收集VB/CB入门文章及技术文章! 欢迎光临编程无限!
     
       
 
当前位置:英文资料 >> System
Icon to tray
  资料类型: System 上传时间: 2001-02-21 阅读次数: 7355



How to add an icon to the tray
One of the questions that occurs most often
in the VB Q and A forum is how to add an icon
to the tray area of the Windows 95 taskbar.
This tip will show you how to add and delete the icon,
and also trap the mouse events.

Declarations
Add the following code to the declarations section of your project.

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

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

Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4

'Make your own constant, e.g.:
Public Const NIF_DOALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP

Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONDOWN = &H204
2) Add a form to the project, and add the following code:

Public Sub CreateIcon()
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
Tic.uFlags = NIF_DOALL
Tic.uCallbackMessage = WM_MOUSEMOVE
Tic.hIcon = Picture1.Picture
Tic.szTip = "Visual Basic Demo Project" & Chr$(0)
erg = Shell_NotifyIcon(NIM_ADD, Tic)
End Sub

Public Sub DeleteIcon()
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
erg = Shell_NotifyIcon(NIM_DELETE, Tic)
End Sub
3) Add two command buttons (command1 and command2) and
a picture box (picture1) to the form.
For the picture property of the form, select an icon.

To to Click event of Command1, add the following code:

CreateIcon
To the Click event of Command2, add the following code:

DeleteIcon
To the MouseMove event of Picture1, add the following code:

X = X / Screen.TwipsPerPixelX
Select Case X
Case WM_LBUTTONDOWN
Caption = "Left Click"
Case WM_RBUTTONDOWN
Caption = "Right Click"
Case WM_MOUSEMOVE
Caption = "Move"
Case WM_LBUTTONDBLCLK
Caption = "Double Click"
End Select
4) Run the project. Click on Command1.
The icon you selected in Picture1 should
appear in the tray area. Now, move the
mouse over the icon. The caption of the
form should change to "Move". Left click
the icon, and the caption will change to
"Left". Right click the icon, and the
caption will change to "Right". Double
Click the icon, and the caption will change
to "Double". To delete the icon from the tray,
click Command2.

Tip by Wolfgang <a9001727@unet.univie.ac.at>



推荐给朋友 点 评( 0 ) 返回前页 关闭此页
   
  本类最热文章排名:
  1.VB6 Apps and Windows Vista
2.Run Time Error Handling Code
3.Printer Control
4.Printing Binary Files
5.Validation at Control-level
6.Turns on Cap’s Lock ...
7.Mouse swap buttons
8.Mouse doubleclick time
9.Creating Screen Savers
10.Justification Of Text On A Printout
   
   
  评论:
 
 
 

 

关于本站 版权声明 联系方法
编程无限 V4.1 Copyright © 1999-2008 21code.com

京ICP备05006938号