free web hosting | free hosting | Web Hosting | Free Website Submission | shopping cart | php hosting
affordable web hosting Pets web page hosting web hosting website hosting web hosting service web hosting web host
 

Main

Aplications

Games

User Controls

Class

Code Snipets

Tips

Add-Ins

Other stuff

Contact

Gest Book

About

Code Please!

The AddToTray function will  add a icon to the tray, if the
operation is not accomplished successfully it returns false, the icon and the
tip that icons has is store in the TrayIcon and the TrayTip properties of our
control.


Public Function AddToTray() As Boolean
Dim Tic As NOTIFYICONDATA
Dim erg As Long

    Tic.cbSize = Len(Tic)
    Tic.hwnd = UserControl.hwnd
    Tic.uID = 1&
    Tic.uFlags = NIF_DOALL
    Tic.uCallbackMessage = WM_MOUSEMOVE
    Tic.hIcon = TrayIcon
    Tic.szTip = m_TrayTip & Chr$(0)
    erg = Shell_NotifyIcon(NIM_ADD, Tic)

If erg = 0 Then
  AddToTray = False
Else
 AddToTray = True
End If
End Function
 


The DeleteFromTray removes a icon from the tray, it returns true or false
depending on the success of the action.



Public Function DeleteFromTray() As Boolean
Dim Tic As NOTIFYICONDATA
Dim erg As Long

    Tic.cbSize = Len(Tic)
    Tic.hwnd = UserControl.hwnd
    Tic.uID = 1&
    erg = Shell_NotifyIcon(NIM_DELETE, Tic)

If erg = 0 Then
  DeleteFromTray = False
Else
 DeleteFromTray = True
End If
End Function
 


The UpdateTray can be used to change a icon already in the tray, we can change
the icon it self and its tip, this ideal for alerting the user of something or displaying a
animation, also  it returns true or false depending on the success of the action.


Public Function UpdateTray() As Boolean

Dim Tic As NOTIFYICONDATA
Dim erg As Long

    Tic.cbSize = Len(Tic)
    Tic.hwnd = UserControl.hwnd
    Tic.uID = 1&
    Tic.uFlags = NIF_DOALL
    Tic.uCallbackMessage = WM_MOUSEMOVE
    Tic.hIcon = TrayIcon
    Tic.szTip = m_TrayTip & Chr$(0)
    erg = Shell_NotifyIcon(NIM_MODIFY, Tic)

If erg = 0 Then
 UpdateTray = False
Else
 UpdateTray = True
End If

End Function

 


We used a user control because the NOTIFYICONDATA type needs a hwnd ( its a handle to a form or control)
it indicates witch control will receive the messages from the tray area icon, witch is our user control.
In the beginning we have declared 5 events that will be raised according to what the user does:

  1. LeftButtonDown - Event triggered when the user clicks with the left mouse button in the tray icon.
  2. RightButtonDown - Event triggered when the user clicks with the right mouse button in the tray icon.
  3. MouseMove -  Event triggered when the user moves the moves the mouse over the tray icon.
  4. LeftMouseDoubleClick - Event triggered when the user clicks twice with the left mouse button in the tray icon.
  5. RightMouseDoubleClick - Event triggered when the user clicks twice with the right mouse button in the tray icon.

Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim x1 As Integer

x1 = x / Screen.TwipsPerPixelX

Select Case x1
    Case WM_LBUTTONDOWN

        RaiseEvent LeftButtonDown


    Case WM_RBUTTONDOWN

        RaiseEvent RightButtonDown


    Case WM_MOUSEMOVE

        RaiseEvent MouseMove


    Case WM_LBUTTONDBLCLK

        RaiseEvent LeftMouseDoubleClick

    Case WM_RBUTTONDBLCLK

        RaiseEvent RightMouseDoubleClick


End Select
 


When we add our control to a form and on the code view we select it we can see the LeftButtonDown, RightButtonDown, MouseMove, LeftMouseDoubleClick and the RightMouseDoubleClick in the Procedure drop down box, these are the events that we raise in our user
control indicating that a user action occurred, just as a Command button as a Click procedure indicating that the user has pressed the
mouse button.

 



TrayControl ] Create Custom Interface Members ] The API Declarations ] [ Code Please! ] Let the drawing begin! ] The Control in use ]

 

Links:

Page Last Updated: 02-07-2003