Results 1 to 2 of 2

Thread: [RESOLVED] Tray icon placement

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2009
    Location
    Nairobi
    Posts
    75

    Resolved [RESOLVED] Tray icon placement

    I happened to come across this code that can place an icon on the System tray. My main worry was, is t realy possible to add a menus? How?

    'Declarations
    Option Explicit

    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 Const NIM_ADD = 0
    Private Const NIM_MODIFY = 1
    Private Const NIM_DELETE = 2
    Private Const NIF_MESSAGE = 1
    Private Const NIF_ICON = 2
    Private Const NIF_TIP = 4

    Private Declare Function Shell_NotifyIconA Lib "SHELL32" _
    (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer
    'TO ADD THE ICON:
    Private Sub mnuadd_Click()
    ' This will add the frmtray icon to the system tray

    Dim retVal As Integer
    Dim nid As NOTIFYICONDATA

    ' This creates our NotifyIconData variable
    nid = setNOTIFYICONDATA( _
    frmTray.hWnd, vbNull, _
    NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
    vbNull, frmTray.Icon, txtTip)

    ' Now we call our API with this variable
    retVal = Shell_NotifyIconA(NIM_ADD, nid)
    MDIMain.Visible = False
    Me.Visible = False
    End Sub

    'I also used this code to delete the icon

    Private Sub mnudelete_Click()
    ' This will delete an existing tray icon
    Dim retVal As Integer
    Dim nid As NOTIFYICONDATA

    nid = setNOTIFYICONDATA( _
    frmTray.hWnd, vbNull, _
    NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
    vbNull, frmTray.Icon, txtTip)

    retVal = Shell_NotifyIconA(NIM_DELETE, nid)
    End Sub

    'The tooltip text was taken care by a text box on the form and the code for changing the icon was

    Private Sub mnumodify_Click()
    ' This will modify an existing tray icon
    Dim retVal As Integer
    Dim nid As NOTIFYICONDATA

    nid = setNOTIFYICONDATA( _
    frmTray.hWnd, vbNull, _
    NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
    vbNull, frmTray.Icon, txtTip)

    retVal = Shell_NotifyIconA(NIM_MODIFY, nid)
    End Sub
    Last edited by bentumkoitaba; Aug 3rd, 2009 at 02:10 AM. Reason: fORGOT SOMETHING

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Tray icon placement

    FYI: Recommend using a hidden picturebox for the tray hWnd vs the form
    Why? If the form is visible and width is > 500 pixels (i.e., maximized) you can inadvertently fire that system tray code just by moving the mouse over the form.

    There are other workarounds also.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width