Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Icon in System Tray

Posted on 1999-06-25
1
Medium Priority
?
259 Views
Last Modified: 2010-05-02
How do I put my VB program in the system tray in stead of in the task bar ?
0
Comment
Question by:SiriusP
[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
1 Comment
 
LVL 2

Accepted Solution

by:
trillo earned 60 total points
ID: 1519824
Hi SiriusP... I already used this code in some other question.... here we go:

I've put two pictureboxes and a menu with some itmes (mnuOn, mnuOff, mnuClose), and the the following code (with full comments)

'The Shell_NotifyIcon API will place an icon in the notification area, assign tool
'tip text, and manage mouse events. This API accepts two parameters. The first
'parameter is the notification message, which tells Shell_NotifyIcon what function
'to perform. There are three valid messages:
'     NIM_ADD (&H0)--registers an icon with the system and places it in the system
'            tray for the first time. You should call it only once for this purpose.
'     NIM_MODIFY (&H1)--makes changes after the icon is registered.
'     NIM_DELETE (&H2)--removes the icon from the system tray. This message is
'            important because icons aren't automatically removed when applications terminate.
'
'Shell_NotifyIcon 's second parameter is a structure containing the information that
'    the API needs in order to process your request. Table A on page 3
'lists these elements and their purposes.

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private 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 t As NOTIFYICONDATA
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_MOUSEMOVE = &H200

'Table A: NOTIFYICONDATA structure
'Element    Purpose
' hWnd      Handle of the window that receives notification messages associated with
'           an icon in the taskbar notification area.
' uID       Application-defined identifier of the taskbar icon.
' uFlags    Array of flags indicating which other structure members contain valid data.
'           This member can be a combination of the following values: NIF_ICON (meaning
'           the hIcon member is valid); NIF_MESSAGE (meaning the uCallbackMessage is
'           valid); and NIF_TIP (meaning the szTip member is valid).
' uCallbackMessage
'           Application-defined message identifier. The system uses this identifier
'           for notification messages it sends to the window (identified by hWnd)
'           whenever a mouse event occurs in the bounding rectangle of the icon.
' hIcon     Handle of the taskbar icon to add, modify, or delete.
' szTip     Tool tip text to display for the taskbar icon.


'IMPORTANT: Note that the images must be icons--if they aren't, the call to
'   Shell_NotifyIcon will fail.


Private Sub Form_Load()
    Me.Visible = False
    t.cbSize = Len(t)
    t.hWnd = Picture1.hWnd
    t.uID = 1&
    t.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    t.uCallbackMessage = WM_MOUSEMOVE
    t.hIcon = Picture1.Picture
    t.szTip = "Shell_NotifyIcon Test" & Chr$(0)
    Shell_NotifyIcon NIM_ADD, t
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'The X parameter of the Picture1_MouseMove event contains the notification message.
'Table B: Shell_NotifyIcon notification messages
'Hex Value Meaning
' '1E00'   Mouse is moving
' '1E0F'   Left button down
' '1E1E'   Left button up
' '1E3C'   Right button down
' '1E4B'   Right button up
' '1E2D'   Left button double-click
' '1E5A'   Right button double-click
    If Hex(X) = "1E3C" Then
        Me.PopupMenu Me.mnuShell
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
'The NIM_DELETE message removes the icon from the notification area. This is important: Without this message, entries in the notification area will
'remain when an application terminates.
    Shell_NotifyIcon NIM_DELETE, t
End Sub

Private Sub mnuClose_Click()
    Unload Me
End Sub

'The Click event for the Off/On menu items toggles the checked values of mnuOff and
'mnuOn and uses the NIM_MODIFY message to change the icon and tool tip text.
'The t.hIcon parameter receives the icon image stored in Pictures' picture value,
'and the event passes a new text string to t.szTip.
Private Sub mnuOff_Click()
    mnuOff.Checked = True
    mnuOn.Checked = False
    t.hIcon = Picture2.Picture
    t.szTip = "Shell_NotifyIcon is Off" & Chr$(0)
    Shell_NotifyIcon NIM_MODIFY, t
End Sub

Private Sub mnuOn_Click()
    mnuOn.Checked = True
    mnuOff.Checked = False
    t.hIcon = Picture1.Picture
    t.szTip = " Shell_NotifyIcon is On " & Chr$(0)
    Shell_NotifyIcon NIM_MODIFY, t
End Sub

Bye
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

721 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