Results 1 to 3 of 3

Thread: [RESOLVED] system tray file menu

  1. #1

    Thread Starter
    Member herbie497's Avatar
    Join Date
    Oct 2006
    Posts
    34

    Resolved [RESOLVED] system tray file menu

    I have this code that minimizes my program to the system tray, and has a file menu function, but I want to change the options to my own. Currently they say 'Option1', 'Option2', and 'Exit'

    The function works perfectly fine, I just want to change the text..
    Here is my form code:

    VB Code:
    1. Option Explicit
    2.  
    3. 'User-defined variable to pass to the Shell_NotiyIcon function
    4. Private Type NOTIFYICONDATA
    5.     cbSize              As Long
    6.     hWnd                As Long
    7.     uId                 As Long
    8.     uFlags              As Long
    9.     uCallBackMessage    As Long
    10.     hIcon               As Long
    11.     szTip               As String * 64
    12. End Type
    13.  
    14. 'Constants for the Shell_NotifyIcon function
    15. Private Const NIM_ADD = &H0
    16. Private Const NIM_MODIFY = &H1
    17. Private Const NIM_DELETE = &H2
    18.  
    19. Private Const WM_MOUSEMOVE = &H200
    20.  
    21. Private Const NIF_MESSAGE = &H1
    22. Private Const NIF_ICON = &H2
    23. Private Const NIF_TIP = &H4
    24.  
    25. Private Const WM_LBUTTONDBLCLK = &H203
    26. Private Const WM_LBUTTONDOWN = &H201
    27. Private Const WM_LBUTTONUP = &H202
    28. Private Const WM_RBUTTONDBLCLK = &H206
    29. Private Const WM_RBUTTONDOWN = &H204
    30. Private Const WM_RBUTTONUP = &H205
    31.  
    32. 'Declare the API function call
    33. Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _
    34.     (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    35.    
    36. Dim nid As NOTIFYICONDATA
    37.  
    38. Public Sub AddIcon(ByVal ToolTip As String)
    39.  
    40.     On Error GoTo ErrorHandler
    41.    
    42.     'Add icon to system tray
    43.     With nid
    44.         .cbSize = Len(nid)
    45.         .hWnd = Me.hWnd
    46.         .uId = vbNull
    47.         .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    48.         .uCallBackMessage = WM_MOUSEMOVE
    49.         .hIcon = Me.Icon
    50.         .szTip = ToolTip & vbNullChar
    51.     End With
    52.     Call Shell_NotifyIcon(NIM_ADD, nid)
    53.    
    54. Exit Sub
    55. ErrorHandler:   'Display error message
    56.     Screen.MousePointer = vbDefault
    57.     MsgBox Err.Description, vbInformation, App.ProductName & " - " & Me.Caption
    58.  
    59. End Sub
    60.  
    61. Private Sub Form_Load()
    62.     WebBrowser.Navigate "(withheld)"
    63.     App.TaskVisible = False
    64.     Call AddIcon("This would be a tooltip...")
    65. End Sub
    66. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    67.  
    68. Dim msg             As Long
    69.  
    70.     On Error GoTo ErrorHandler
    71.    
    72.     'Respond to user interaction
    73.     msg = X / Screen.TwipsPerPixelX
    74.     Select Case msg
    75.            
    76.         Case WM_LBUTTONDBLCLK
    77.             'nothing
    78.    
    79.         Case WM_LBUTTONDOWN
    80.             'nothing
    81.        
    82.         Case WM_LBUTTONUP
    83.             If Me.WindowState = vbMinimized Then
    84.                 Me.WindowState = vbNormal
    85.                 Me.Show
    86.             Else
    87.                 Me.WindowState = vbMinimized
    88.                 Me.Hide
    89.             End If
    90.            
    91.         Case WM_RBUTTONDBLCLK
    92.             'nothing
    93.        
    94.         Case WM_RBUTTONDOWN
    95.             'nothing
    96.        
    97.         Case WM_RBUTTONUP
    98.             Call PopupMenu(mnuFile, vbPopupMenuRightAlign)
    99.            
    100.     End Select
    101.    
    102. Exit Sub
    103. ErrorHandler:   'Display error message
    104.     Screen.MousePointer = vbDefault
    105.     MsgBox Err.Description, vbInformation, App.ProductName & " - " & Me.Caption
    106.  
    107. End Sub
    108.  
    109. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    110.  
    111.     'Remove icon from system tray
    112.     Call Shell_NotifyIcon(NIM_DELETE, nid)
    113.  
    114. End Sub
    115.  
    116. Private Sub mnuFileArray_Click(Index As Integer)
    117.  
    118.     Select Case Index
    119.         Case 0  'Normal
    120.             Me.WindowState = vbNormal
    121.                    
    122.         Case 1  'Minimized
    123.             Me.WindowState = vbMinimized
    124.                    
    125.         Case 4  'Exit
    126.             Unload Me
    127.             End
    128.    
    129.     End Select
    130.    
    131. End Sub
    132.  
    133. Private Sub cmdHome_Click()
    134.     WebBrowser.Navigate "(withheld)"
    135. End Sub
    136.  
    137. Private Sub cmdArchive_Click()
    138.     WebBrowser.Navigate "(withheld)"
    139. End Sub
    140.  
    141. Private Sub cmdPost_Click()
    142.     WebBrowser.Navigate "(withheld)"
    143. End Sub
    144.  
    145. Private Sub cmdProfile_Click()
    146.     WebBrowser.Navigate "(withheld)"
    147. End Sub
    148.  
    149. Private Sub cmdExit_Click()
    150.     Unload frmBrowser
    151. End Sub
    152.  
    153. Private Sub cmdMini_Click()
    154.     frmSysTrayIcon.WindowState = vbMinimized
    155. End Sub
    156.  
    157. Private Sub cmdLogOut_Click()
    158.     WebBrowser.Navigate "(withheld)"
    159. End Sub

    Thanks for any help!!

  2. #2
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Re: system tray file menu


    Post the whole project in the zip file
    here not getting option1 any where in your project

  3. #3

    Thread Starter
    Member herbie497's Avatar
    Join Date
    Oct 2006
    Posts
    34

    Re: system tray file menu

    Sorry for the long reply, been away..

    Attached is the whole project
    Attached Files Attached Files

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