Results 1 to 5 of 5

Thread: Iconized application

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    Singapore
    Posts
    98

    Question

    Hi,

    I wish to ask if anyone could explain to me how i can run my programs in iconized form in the system tray.

  2. #2
    Junior Member
    Join Date
    Aug 2000
    Posts
    18
    Da illest G in da room

  3. #3
    Guest
    Add this to a module:
    Code:
    Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    
    Public 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
    
    Public Const NIF_ICON = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_TIP = &H4
    Public Const NIF_ALL = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
    
    Public Const NIM_ADD = &H0
    Public Const NIM_DELETE = &H2
    Public Const NIM_MODIFY = &H1
    
    Public Const WM_MOUSEMOVE = &H200
    Public Const WM_RBUTTONUP = &H205
    Add a PictureBox to your Form and name it picTray.
    Set the ScaleMode property of picTray to 3 - Pixels.
    Add this to the MouseMove event of picTray:
    Code:
    Dim wMsg As Long
    wMsg = X
    
    Select Case wMsg
        Case WM_RBUTTONUP
            'The user has clicked on your icon
            'with the right mouse button. You can
            'add code to pop-up a menu here.
    End Select
    Set the Picture property of picTray to an icon. It's important to add an icon and not a bmp!

    Add this to the Load event of the Form:
    Code:
    Dim NID As NOTIFYICONDATA
    
    With NID
        .cbSize = Len(NID)
        .hWnd = picTray.hWnd
        .uID = 1
        .uFlags = NIF_ALL
        .uCallbackMessage = WM_MOUSEMOVE
        .hIcon = picTray.Picture.Handle
        .szTip = "This is my app!" & Chr(0)
    End With
    
    Shell_NotifyIcon NIM_ADD, NID
    In the Unload event of your Form add this:
    Code:
    Dim NID As NOTIFYICONDATA
    
    With NID
        .cbSize = Len(NID)
        .hWnd = picTray.hWnd
        .uID = 1
        .uFlags = NIF_ALL
        .uCallbackMessage = WM_MOUSEMOVE
        .hIcon = picTray.Picture.Handle
        .szTip = "This is my app!" & Chr(0)
    End With
    
    Shell_NotifyIcon NIM_DELETE, NID
    I wrote the code right to the post so let me know if it works.

    BTW: If you intend to show your form, you might want to set the Visible property of picTray to False.

    [Edited by Sc0rp on 10-07-2000 at 07:35 AM]

  4. #4
    Guest
    This is a simpler way of the above post..a little different as well .

    Code:
    'Module code:
    
    Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    Public Const NIM_ADD = &H0
    Public Const NIM_MODIFY = &H1
    Public Const NIM_DELETE = &H2
    Public Const NIF_MESSAGE = &H1
    Public Const NIF_ICON = &H2
    Public Const NIF_TIP = &H4
    Public Const WM_LBUTTONUP = &H202
    Public Const WM_RBUTTONUP = &H205
    Public Const WM_MOUSEMOVE = &H200
    
    
    Public 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
    
    Public VBGTray As NOTIFYICONDATA
    
    
    'Form Declarations:
    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
    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

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I recommend the OCX control from Kedaman (KedTray.ocx) because it's really easy to use.
    Look at http://www.kedaman.com for the control!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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