Results 1 to 4 of 4

Thread: A System Tray Icon Like Napster??

  1. #1

    Thread Starter
    Lively Member jonvantuyl's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    75

    Angry

    I was wondering what the code for creating a system tray icon would be? I need it to be where if they click the close button then it just goes to the system tray. then when they click on the image the program restores. Sortta like napster?

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Lively Member jonvantuyl's Avatar
    Join Date
    Nov 2000
    Location
    Michigan
    Posts
    75

    Wink

    THANKS

  4. #4
    Guest
    This code may be better--clear things up.

    Code:
    Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    Private Const NIM_ADD = &H0
    Private Const NIM_MODIFY = &H1
    Private Const NIM_DELETE = &H2
    Private Const NIF_MESSAGE = &H1
    Private Const NIF_ICON = &H2
    Private Const NIF_TIP = &H4
    Private Const WM_LBUTTONUP = &H202
    Private Const WM_RBUTTONUP = &H205
    Private Const WM_MOUSEMOVE = &H200
    
    
    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 VBGTray As NOTIFYICONDATA
    
    Private Sub GoSystemTray()
      VBGTray.cbSize = Len(VBGTray)
      VBGTray.hwnd = Me.hwnd
      VBGTray.uId = vbNull
      VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
      VBGTray.ucallbackMessage = WM_MOUSEMOVE
      VBGTray.hIcon = Me.Icon
      'tool tip text
      VBGTray.szTip = Me.Caption & vbNullChar
      Call Shell_NotifyIcon(NIM_ADD, VBGTray)
      App.TaskVisible = False   'remove application from taskbar
      Me.Hide
    End Sub
    
    'Form Code:
    
    Private Sub Form_MouseMove(button As Integer, Shift As Integer, X As Single, Y As Single)
      Static lngMsg As Long
      Static blnFlag As Boolean
      Dim result As Long
    lngMsg = X / Screen.TwipsPerPixelX
      If blnFlag = False Then
            blnFlag = True
            Select Case lngMsg
            'right-click
            Case WM_RBUTTONUP
              result = SetForegroundWindow(Me.hwnd)
              PopupMenu MyPopUpMenu
             Case WM_LBUTTONUP
              result = SetForegroundWindow(Me.hwnd)
              PopupMenu MyPopUpMenu
            End Select
            blnFlag = False
     End If
    End Sub
    
    Private Sub Form_Resize()
    If Me.WindowState = 1 Then
    Call GoSystemTray
    ElseIf Me.WindowState = 0 Then
      VBGTray.cbSize = Len(VBGTray)
      VBGTray.hwnd = Me.hwnd
      VBGTray.uId = vbNull
      Call Shell_NotifyIcon(NIM_DELETE, VBGTray)
    End If
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
      VBGTray.cbSize = Len(VBGTray)
      VBGTray.hwnd = Me.hwnd
      VBGTray.uId = vbNull
      Call Shell_NotifyIcon(NIM_DELETE, VBGTray)
      Unload Me
      Set Form1 = Nothing
      End
    End Sub

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