CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: System Tray

  1. #1
    Join Date
    Jan 2000
    Posts
    45

    System Tray

    how do you put your program icon in the system tray, i beleive i have asked this question before but either the code didn't work, or no1 replied.


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: System Tray

    Here's some code I put together, add it to a Form with a Picturebox, set the Forms ShowInTaskbar Property to False and it should work fine:

    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 Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (byval dwMessage as Long, lpData as NOTIFYICONDATA) as Long

    private Const NIF_ICON = &H2
    private Const NIF_MESSAGE = &H1
    private Const NIF_TIP = &H4
    private Const NIM_ADD = &H0
    private Const NIM_DELETE = &H2
    private Const NIM_MODIFY = &H1
    private Const WM_MOUSEMOVE = &H200
    private Const WM_LBUTTONDBLCLK = &H203
    private Const WM_LBUTTONDOWN = &H201
    private Const WM_RBUTTONDOWN = &H204

    private tTrayIcon as NOTIFYICONDATA

    private Sub Form_Load()
    'Create a Tray Icon
    Picture1.Visible = false
    With tTrayIcon
    'Image to Display in the System Tray
    .hIcon = Icon
    'Window Handle to Recieve Tray Icon Messages
    .hwnd = Picture1.hwnd
    'Tray Icon Tool Tip
    .szTip = "My Tray Icon" & Chr(0)
    'Message to Direct to Assign Hwnd
    .uCallbackMessage = WM_MOUSEMOVE
    'What to Change/Add to this Tray Icon
    .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
    'Unique ID for the Tray Icon
    .uID = 1
    .cbSize = len(tTrayIcon)
    End With
    'Add the Icon to the Tray
    Shell_NotifyIcon NIM_ADD, tTrayIcon
    End Sub

    private Sub Form_Resize()
    DoEvents
    If WindowState = vbMinimized then
    'If the Form is Minimized, Hide it.
    Hide
    End If
    End Sub

    private Sub Form_Unload(Cancel as Integer)
    'Remove the Tray Icon
    Shell_NotifyIcon NIM_DELETE, tTrayIcon
    End Sub

    private Sub Picture1_MouseMove(Button as Integer, Shift as Integer, X as Single, Y as Single)
    'This Sub Recieves the WM_MOUSEMOVE Message from the Tray Icon
    Select Case ScaleX(X, vbTwips, vbPixels)
    Case WM_RBUTTONDOWN
    'Show Popup Menu Here
    Case WM_LBUTTONDBLCLK
    'Show the Form Here
    WindowState = vbNormal
    Show
    End Select
    End Sub




    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

  3. #3
    Join Date
    Aug 1999
    Location
    US, Florida
    Posts
    817

    Re: System Tray

    Sorry for improper language that I'm about to use Mr.PanasonicSubz, but why are you *****ing about something that you didn't read? It's not our problem that you have attitude problem, that you DO NOT read replys to your OWN postings, and that you never rate anyones CORRECT reply? People at this forum have no intention answering your postings because you never rate them and/or you start to blame others for your own "mistakes", but people still answer your postings, so you should just shut up and act like normal person by reading replys and rating correct answers

    Have a nice day.


  4. #4
    Join Date
    Sep 1999
    Location
    Germany, Cologne
    Posts
    83

    Re: System Tray

    Do you want a DLL which contains all the C++-Code?


    You only must Declare 3 functions:
    AddTaskbarIcon
    ModifyTaskbarIcon and
    DeleteTaskbarIcon.


    In the beginning I wanted to write this (non-ActiveX; dynamic link; it requires nothing else, no registry etc. and is faster than VB; it's size is only 32KB [for you free to use in your apps]) library for my C and C++ apps, but it also works with VB fine.

    But to react to window-messages you must get the WM_-Message by calling the function
    GetNotifyIconMessageNumber fron this DLL.

    That's all!

    If you'd like it, send me a private message and I'll send it to your e-mail address; if you like some example code, too.


    Good luck!

    'CMichael


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

Featured