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

Thread: Systray

  1. #1
    Join Date
    Nov 1999
    Location
    Austria
    Posts
    53

    Systray

    How can I write a program which is not shown in the Task Bar but has an Icon in the SysTray.

    Please help

    mfG Pueromane


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

    Re: Systray

    Add this to a Form with an Invisible Picturebox and Set the ShowInTaskBar Property to False.

    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
    .hIcon = Icon
    .hwnd = Picture1.hwnd
    .szTip = "My Tray Icon" & Chr(0)
    .uCallbackMessage = WM_MOUSEMOVE
    .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
    .uID = 1
    .cbSize = len(tTrayIcon)
    End With
    Shell_NotifyIcon NIM_ADD, tTrayIcon
    End Sub

    private Sub Form_Resize()
    DoEvents
    If WindowState = vbMinimized then
    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)
    Select Case ScaleX(X, vbTwips, vbPixels)
    Case WM_RBUTTONDOWN
    'Show Popup Menu
    Case WM_LBUTTONDBLCLK
    'Show the Form
    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
    Nov 1999
    Location
    Austria
    Posts
    53

    Re: Systray

    Thanks it works fine

    mfg Pueromane


  4. #4
    Join Date
    Jul 1999
    Posts
    145

    Re: Systray

    I don't follow how the Select Case statement works here. Why would the ScaleX function return a match to the button click constants?

    Thanks in advance.


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

    Re: Systray

    Because in the TrayIcon Structure we are telling it to send all Messages to the Picturebox Window Handle, and we tell it to use the WM_MOUSEMOVE Message, which triggers the Picture1_MouseMove() Event, because of this it is now passing the wParam and lParam Values Which end up in the X Parameter.
    In Order to get the Value of the wParam which is a Long Data Type, we Get the Result of X in Pixels.


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

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