Results 1 to 11 of 11

Thread: SysTray

  1. #1

    Thread Starter
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Add an Invisible Picturebox to your Form, then Paste this Code:
    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
    If you want it even simpler I believe there's an OCX available on this site somewhere, which bascially does all this in the background.

    Only downside is you have to ship the OCX with your Project.


    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  2. #2
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Post

    Does anyone know how i can
    put my program in the
    System Tray in an EASY way????

    / CyberCarsten

  3. #3
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Post

    Thank you Aaron!
    I'll try it!

  4. #4
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Post

    When i place the following code
    in my 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

    VB marks : Shell_NotifyIcon NIM_ADD, tTrayIcon
    and the following error occuors:

    Compile Error
    Sub or Function not defined

    What is wrong??

    / CyberCarsten

  5. #5
    Junior Member
    Join Date
    Nov 1999
    Posts
    25

    Post

    I'd like to add a question here.

    I'd like to use a systray icon for my program, but I'd like the program to load as a tray icon and then allow the form1 to be shown once the user click the icon in the tray and select for the program to be seen from a drop down menu.

    Anyone know how to do this?

    Thanks,
    MiDaWe

  6. #6

    Thread Starter
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Just Set the Forms Visible Property to False, the Load Event will still trigger creating the Tray Icon, then in the Right Click Section of the Select Case Statement, Display the PopupMenu from which you can set the Forms Visible Property to True.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  7. #7
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Try copying all of Aaron's code and not just a part. The code works on an empty form with only an invisible PictureBox in it.

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879
    AIM: RYoni69

  8. #8
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Post

    It still doesn't work!
    Could someone please send me the project???

    [email protected]

    / CyberCarsten

  9. #9

    Thread Starter
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Set the Forms Visible Property to False, Add an Invisible Picturebox.
    Create a Menu Call mnuPopup and add the Sub Items; mnuShowForm1 and mnuExit, make sure the Visible Property of mnuPopup is False (Unchecked).

    Then paste All this code into the Forms General Section..
    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 WM_MOUSEMOVE = &H200
    Private Const WM_RBUTTONUP = &H205
    
    Private tTrayIcon As NOTIFYICONDATA
    
    Private Sub Form_Load()
        With tTrayIcon
            .hIcon = Icon
            .hwnd = Picture1.hwnd
            .szTip = Caption & 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()
        If WindowState = vbMinimized Then
            Hide
        End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
        Shell_NotifyIcon NIM_DELETE, tTrayIcon
    End Sub
    
    Private Sub mnuExit_Click()
        Unload Me
    End Sub
    
    Private Sub mnuShowForm1_Click()
        Show
    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_RBUTTONUP
            Me.PopupMenu mnuPopup
        End Select
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

  10. #10
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Post

    Hi Aaron!
    Thank you for all your help!!
    It finally worked!!!

    And just one last Question:
    Can i call the same procedure with a button??

    Yours Sincierly
    / CyberCarsten

  11. #11

    Thread Starter
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    The Form is Shown from the mnuShowForm1 Click Event, so you can either call that Event from the Command Button or Simple Show the Form, eg.
    Code:
    Private Sub Command1_Click()
        mnuShowForm1_Click
    End Sub
    or..
    Code:
    Private Sub Command1_Click()
        Show
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

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