VB icon

How to add an icon to the tray

Email
Submitted on: 1/3/2015 4:40:00 AM
By: King (from psc cd)  
Level: Not Given
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 660
 
     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.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :How to add an icon to the tray
'**************************************
 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
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: How to add an icon to the tray
' Description: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.
' By: King (from psc cd)
'
' Assumes:Create two command buttons (command1 and command2) and a picture box (picture1) to the form. For the picture property of the Picture Box select the icon you want to be displayed in the tray.
'**************************************

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
Private Sub Command1_Click()
CreateIcon
End Sub
Private Sub Command2_Click()
DeleteIcon
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
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
End Sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/8/2017 1:08:11 AMrazzak

no icon show
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.