Results 1 to 3 of 3

Thread: [RESOLVED] Need help to dismiss the Tray Notification after 2 seconds.

  1. #1

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    Resolved [RESOLVED] Need help to dismiss the Tray Notification after 2 seconds.

    Hi all,

    Below is the code I have to create systray icon with sys menu and notification tip. It works fine. But, the notification tip is not dismissing automatically. I need help to dismiss the notification tip automatically after 2 seconds or after few seconds. How can I achieve that?

    Code for Class Module:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    4.  
    5. Private Const APP_SYSTRAY_ID = 999
    6. Private Const NOTIFYICON_VERSION = &H3
    7. Private Const NIF_MESSAGE = &H1
    8. Private Const NIF_ICON = &H2
    9. Private Const NIF_TIP = &H4
    10. Private Const NIF_INFO = &H10
    11. Private Const NIM_ADD = &H0
    12. Private Const NIM_MODIFY = &H1
    13. Private Const NIM_DELETE = &H2
    14. Private Const NIM_SETVERSION = &H4
    15. Private Const NIS_SHAREDICON = &H2
    16. Private NOTIFYICONDATA_SIZE As Long
    17. Private Const WM_MOUSEMOVE = &H200
    18. Private Const WM_LBUTTONDBLCLK = &H203
    19. Private Const WM_RBUTTONUP = &H205
    20.  
    21. Private Type GUID
    22.     Data1 As Long
    23.     Data2 As Integer
    24.     Data3 As Integer
    25.     Data4(7) As Byte
    26. End Type
    27.  
    28. Private Type NOTIFYICONDATA
    29.     cbSize As Long
    30.     hWnd As Long
    31.     uID As Long
    32.     uFlags As Long
    33.     uCallbackMessage As Long
    34.     hIcon As Long
    35.     szTip As String * 128
    36.     dwState As Long
    37.     dwStateMask As Long
    38.     szInfo As String * 256
    39.     uTimeoutAndVersion As Long
    40.     szInfoTitle As String * 64
    41.     dwInfoFlags As Long
    42.     guidItem As GUID
    43. End Type
    44.  
    45. Public Sub ShellTrayAdd(hWindow As Long, hIcon As Long)
    46.     Dim nid As NOTIFYICONDATA
    47.     If NOTIFYICONDATA_SIZE = 0 Then NOTIFYICONDATA_SIZE = 504
    48.     With nid
    49.         .cbSize = NOTIFYICONDATA_SIZE
    50.         .hWnd = hWindow
    51.         .uID = APP_SYSTRAY_ID
    52.         .uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    53.         .dwState = NIS_SHAREDICON
    54.         .uCallbackMessage = WM_MOUSEMOVE
    55.         .hIcon = hIcon
    56.         .szTip = "testing" & vbNullChar
    57.         .uTimeoutAndVersion = NOTIFYICON_VERSION
    58.     End With
    59.     Call Shell_NotifyIcon(NIM_ADD, nid)
    60.     Call Shell_NotifyIcon(NIM_SETVERSION, nid)
    61. End Sub
    62.  
    63. Public Sub ShellTrayRemove(hWindow As Long)
    64.     Dim nid As NOTIFYICONDATA
    65.     If NOTIFYICONDATA_SIZE = 0 Then NOTIFYICONDATA_SIZE = 504
    66.     With nid
    67.         .cbSize = NOTIFYICONDATA_SIZE
    68.         .hWnd = hWindow
    69.         .uID = APP_SYSTRAY_ID
    70.     End With
    71.     Call Shell_NotifyIcon(NIM_DELETE, nid)
    72. End Sub
    73.  
    74. Public Sub ShellTrayModifyTip(hWindow As Long, nIconIndex As Long, strText As String)
    75.     Dim nid As NOTIFYICONDATA
    76.     If NOTIFYICONDATA_SIZE = 0 Then NOTIFYICONDATA_SIZE = 504
    77.     With nid
    78.         .cbSize = NOTIFYICONDATA_SIZE
    79.         .hWnd = hWindow
    80.         .uID = APP_SYSTRAY_ID
    81.         .uFlags = NIF_INFO
    82.         .dwInfoFlags = nIconIndex
    83.         .szInfoTitle = "testing" & vbNullChar
    84.         .szInfo = strText & vbNullChar
    85.     End With
    86.     Call Shell_NotifyIcon(NIM_MODIFY, nid)
    87. End Sub
    88.  
    89. Public Sub GenerateSysMenu(X As Single, mnuAbout As Boolean, mnuExit As Boolean)
    90.     Static Popped As Boolean
    91.     Static Msg As Long
    92.  
    93.     Msg = X / Screen.TwipsPerPixelX
    94.     If Popped = False Then
    95.         Popped = True
    96.         Select Case Msg
    97.         Case WM_LBUTTONDBLCLK
    98.             mnuAbout = True
    99.         Case WM_RBUTTONUP
    100.             mnuExit = True
    101.         End Select
    102.         Popped = False
    103.     End If
    104. End Sub
    Code in Form:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim cSysTray As Class1
    4.  
    5. Private Sub Form_Load()
    6.     Set cSysTray = New Class1
    7.  
    8.     Text1.Text = "Test message notification"
    9.  
    10.     Call cSysTray.ShellTrayAdd(Me.hWnd, Me.Icon)
    11. End Sub
    12.  
    13. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    14.     Dim mnuAbout As Boolean, mnuExit As Boolean
    15.     Call cSysTray.GenerateSysMenu(X, mnuAbout, mnuExit)
    16.     Select Case True
    17.     Case mnuAbout
    18.         mnuPopupAbout_Click
    19.     Case mnuExit
    20.         PopupMenu mnuPopup, 2, , , mnuPopupAbout
    21.     End Select
    22. End Sub
    23.  
    24. Private Sub Form_Unload(Cancel As Integer)
    25.     Call cSysTray.ShellTrayRemove(Me.hWnd)
    26. End Sub
    27.  
    28. Private Sub Command2_Click()
    29.     Call cSysTray.ShellTrayModifyTip(Me.hWnd, 1, Text1.Text)
    30. End Sub
    31.  
    32. Private Sub mnuPopupAbout_Click()
    33.     Call MsgBox("Testing", vbInformation, "About...")
    34. End Sub
    35.  
    36. Private Sub mnuPopUpExit_Click()
    37.     Unload Me
    38. End Sub
    Please help!

    Thanks,

    Kanna.

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member csKanna's Avatar
    Join Date
    Dec 2005
    Location
    Tech-Tips-Now.com
    Posts
    339

    Re: [RESOLVED] Need help to dismiss the Tray Notification after 2 seconds.

    thanks a lot

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