Solved

Running a Program in the Bottom Taskbar

Posted on 2000-05-08
3
185 Views
Last Modified: 2010-05-02
I'm damned if I can remember what it's called but, How do I get a VB program to run in the sidebar (the area where the time and screen resolution shows, down the bottom right hand side of Windows)?

Thanks
0
Comment
Question by:MrTimewalk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 2787937
go to this site Elliot has an excellent example of how to achieve this, and explains it:
                    http://www.spnc.demon.co.uk/index/vb_idx.htm
0
 
LVL 18

Accepted Solution

by:
deighton earned 50 total points
ID: 2787943
The System Tray


                    '//Enter in a module
                    Option Explicit

                    Public OldWindowProc As Long
                    Public TheForm As Form
                    Public TheMenu As Menu

                    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 Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage
                    As Long, lpData As NOTIFYICONDATA) As Long

                    Public Const WM_USER = &H400
                    Public Const WM_LBUTTONUP = &H202
                    Public Const WM_MBUTTONUP = &H208
                    Public Const WM_RBUTTONUP = &H205
                    Public Const TRAY_CALLBACK = (WM_USER + 1001&)
                    Public Const GWL_WNDPROC = (-4)
                    Public Const GWL_USERDATA = (-21)
                    Public Const NIF_ICON = &H2
                    Public Const NIF_TIP = &H4
                    Public Const NIM_ADD = &H0
                    Public Const NIF_MESSAGE = &H1
                    Public Const NIM_MODIFY = &H1
                    Public Const NIM_DELETE = &H2

                    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

                    Private TheData As NOTIFYICONDATA
                    ' *********************************************
                    ' The replacement window proc.
                    ' *********************************************
                    Public Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As
                    Long, ByVal lParam As Long) As Long
                    Const WM_SYSCOMMAND = &H112
                    Const SC_MAXIMIZE = &HF030&
                    Const SC_MINIMIZE = &HF020&
                    Const SC_RESTORE = &HF120&
                         
                        If Msg = TRAY_CALLBACK Then
                            ' The user clicked on the tray icon.
                            ' Look for click events.
                            If lParam = WM_LBUTTONUP Then
                                ' On left click, show the form.
                                TheForm.Show
                                If TheForm.WindowState = vbMinimized Then _
                                    TheForm.WindowState = TheForm.LastState
                                TheForm.SetFocus
                                Exit Function
                            End If
                            If lParam = WM_RBUTTONUP Then
                                ' On right click, show the menu.
                                TheForm.PopupMenu TheMenu
                                Exit Function
                            End If
                        End If
                         
                        If Msg = WM_SYSCOMMAND Then
                            If wParam = SC_MINIMIZE Then
                                TheForm.Hide
                                TheForm.SetTrayMenuItems vbMinimized
                                Exit Function
                            ElseIf wParam = SC_RESTORE Then
                                If Not TheForm.Visible Then
                                    TheForm.Show
                                    TheForm.SetTrayMenuItems vbNormal
                                    Exit Function
                                End If
                            End If
                        End If
                         
                        ' Send other messages to the original
                        ' window proc.
                        NewWindowProc = CallWindowProc( _
                            OldWindowProc, hwnd, Msg, _
                            wParam, lParam)
                    End Function
                    ' *********************************************
                    ' Add the form's icon to the tray.
                    ' *********************************************
                    Public Sub AddToTray(frm As Form, mnu As Menu)
                        ' ShowInTaskbar must be set to False at
                        ' design time because it is read-only at
                        ' run time.

                        ' Save the form and menu for later use.
                        Set TheForm = frm
                        Set TheMenu = mnu
                         
                        ' Install the new WindowProc.
                        OldWindowProc = SetWindowLong(frm.hwnd, _
                            GWL_WNDPROC, AddressOf NewWindowProc)
                         
                        ' Install the form's icon in the tray.
                        With TheData
                            .uID = 0
                            .hwnd = frm.hwnd
                            .cbSize = Len(TheData)
                            .hIcon = frm.Icon.Handle
                            .uFlags = NIF_ICON
                            .uCallbackMessage = TRAY_CALLBACK
                            .uFlags = .uFlags Or NIF_MESSAGE
                            .cbSize = Len(TheData)
                        End With
                        Shell_NotifyIcon NIM_ADD, TheData
                    End Sub
                    ' *********************************************
                    ' Remove the icon from the system tray.
                    ' *********************************************
                    Public Sub RemoveFromTray()
                        ' Remove the icon from the tray.
                        With TheData
                            .uFlags = 0
                        End With
                        Shell_NotifyIcon NIM_DELETE, TheData
                         
                        ' Restore the original window proc.
                        SetWindowLong TheForm.hwnd, GWL_WNDPROC, _
                            OldWindowProc
                    End Sub
                    ' *********************************************
                    ' Set a new tray tip.
                    ' *********************************************
                    Public Sub SetTrayTip(tip As String)
                        With TheData
                            .szTip = tip & vbNullChar
                            .uFlags = NIF_TIP
                        End With
                        Shell_NotifyIcon NIM_MODIFY, TheData
                    End Sub
                    ' *********************************************
                    ' Set a new tray icon.
                    ' *********************************************
                    Public Sub SetTrayIcon(pic As Picture)
                        ' Do nothing if the picture is not an icon.
                        If pic.Type <> vbPicTypeIcon Then Exit Sub

                        ' Update the tray icon.
                        With TheData
                            .hIcon = pic.Handle
                            .uFlags = NIF_ICON
                        End With
                        Shell_NotifyIcon NIM_MODIFY, TheData
                    End Sub



                    'Define menus according to code
                    '//Enter in Form
                    Private Sub mnuTrayMinimize_Click()
                        WindowState = vbMinimized
                    End Sub


                    Private Sub mnuTrayMove_Click()
                        SendMessage hwnd, WM_SYSCOMMAND, _
                            SC_MOVE, 0&
                    End Sub


                    Private Sub mnuTrayRestore_Click()
                        SendMessage hwnd, WM_SYSCOMMAND, _
                            SC_RESTORE, 0&
                    End Sub


                    Private Sub mnuTraySize_Click()
                        SendMessage hwnd, WM_SYSCOMMAND, _
                            SC_SIZE, 0&
                    End Sub
0
 

Author Comment

by:MrTimewalk
ID: 2787954
Nice on Thanks!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question