Solved

System Tray Icon

Posted on 1998-05-05
5
245 Views
Last Modified: 2008-02-01
I'm trying to run an application written in VB5 on the background, with an icon on the system tray (where the time also is in the taskbar). Can anyone tell me how to do this ?

Michel
0
Comment
Question by:sioux
[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
5 Comments
 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1440474
0
 

Expert Comment

by:SteveB032698
ID: 1440475
It isn't necessary to use an OCX in VB5.  A simple API call to ShellNotifyIcon  in a .bas module can do the same thing without the overhead of the OCX.  It is also FREE.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1440476
SteveB:
This ocx is freeware.  Also, to use API for placing and controlling tray icons is possible, but you need callbacks and generally more code than is necessary.  Why reinvent the wheel?
0
 

Expert Comment

by:tad
ID: 1440477
I use the following code - downloaded from http://www.sourcesite.simplenet.com/Frames.html



'Copyright 1997 Karland International
'You may use this BAS file as much as you want as
'long as you leave all the contents in it..

'For starters to make this work you need to do one thing.
'Create a menu called mnuSystemtray.  Create as many options
'you want under it.  This will be what pops up when they right
'click on the icon while it's in the system tray..  After you have
'created this menu then make sure that it is invisible and
'that's all there is too it..

'***The below goes in a Module (BAS File)***
'Icon in systemtray
Public Const WM_LBUTTONDBLCLICK = &H203
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
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

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 VBGTray As NOTIFYICONDATA
Declare Function Shell_NotifyIcon Lib "shell32" Alias _
    "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long


'Examample of use:
'****The below goes into your main form*****
'****Copy the below and take out the first ' in every line****
'Private Sub GoSystemTray()
'  VBGTray.cbSize = Len(VBGTray)
'  VBGTray.hwnd = Me.hwnd
'  VBGTray.uId = vbNull
'  VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
'  VBGTray.ucallbackMessage = WM_MOUSEMOVE


'  VBGTray.hIcon = Me.Icon
'  'tool tip text
'  VBGTray.szTip = Me.Caption & vbNullChar

'  Call Shell_NotifyIcon(NIM_ADD, VBGTray)

'  App.TaskVisible = False   'remove application from taskbar
'  Me.Hide

'End Sub

'Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
'  Static lngMsg As Long
'  Static blnFlag As Boolean
'  Dim result As Long

'lngMsg = x / Screen.TwipsPerPixelX

'  If blnFlag = False Then
'        blnFlag = True
'        Select Case lngMsg
'        'doubleclick
'        Case WM_LBUTTONDBLCLICK
'            Me.WindowState = 0
'            Me.Show
'        'right-click
'        Case WM_RBUTTONUP
'          result = SetForegroundWindow(Me.hwnd)
'          Me.PopupMenu mnuSystemtray        '<---You will need to create a menu called mnuSystemtray
'        End Select
'        blnFlag = False
' End If
'End Sub

'Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

'  VBGTray.cbSize = Len(VBGTray)
'  VBGTray.hwnd = Me.hwnd
'  VBGTray.uId = vbNull

'  Call Shell_NotifyIcon(NIM_DELETE, VBGTray)

'End Sub

'Private Sub Form_Load()
'VBGTray.cbSize = Len(VBGTray)
'VBGTray.hwnd = Me.hwnd
'VBGTray.uId = vbNull
'VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
'VBGTray.ucallbackMessage = WM_MOUSEMOVE


'VBGTray.hIcon = Me.Icon
''tooltiptext
'VBGTray.szTip = Me.Caption & vbNullChar

'Call Shell_NotifyIcon(NIM_ADD, VBGTray)

'mnuSystemtray.Visible = False
'End Sub

'Private Sub Form_Resize()
'    If Me.WindowState = 1 Then
'        GoSystemTray
'    End If
'End Sub

0
 
LVL 1

Author Comment

by:sioux
ID: 1440478
Thanx. The OCX works fine for me.
Michel
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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