CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 1999
    Posts
    21

    Running app in systray only

    Does anyone know how to make a VB program run in the systray only?


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

    Re: Running app in systray only

    Set the Forms ShowInTaskBar Property to False then add this code..

    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

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