Results 1 to 3 of 3

Thread: refresh tray icon

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    refresh tray icon

    Is there a way to refresh the taskbar's tray icon? I had to taskkill a third party program and need that icon to go away.

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: refresh tray icon

    Try this

    Form code
    vb Code:
    1. Private Type STARTUPINFO
    2.           cb As Long
    3.           lpReserved As String
    4.           lpDesktop As String
    5.           lpTitle As String
    6.           dwX As Long
    7.           dwY As Long
    8.           dwXSize As Long
    9.           dwYSize As Long
    10.           dwXCountChars As Long
    11.           dwYCountChars As Long
    12.           dwFillAttribute As Long
    13.           dwFlags As Long
    14.           wShowWindow As Integer
    15.           cbReserved2 As Integer
    16.           lpReserved2 As Long
    17.           hStdInput As Long
    18.           hStdOutput As Long
    19.           hStdError As Long
    20.        End Type
    21.      
    22.        Private Type PROCESS_INFORMATION
    23.           hProcess As Long
    24.           hThread As Long
    25.           dwProcessId As Long
    26.           dwThreadID As Long
    27.        End Type
    28.      
    29.        Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
    30.           hHandle As Long, ByVal dwMilliseconds As Long) As Long
    31.     'API Constants
    32.     Const SMTO_BLOCK = &H1
    33.     Const SMTO_ABORTIFHUNG = &H2
    34.     Const WM_NULL = &H0
    35.     Const WM_CLOSE = &H10
    36.     Const PROCESS_ALL_ACCESS = &H1F0FFF
    37.     'API functions
    38.     Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, _
    39.     lpdwProcessId As Long) As Long
    40.      
    41.     Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
    42.     ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    43.      
    44.     Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" _
    45.     (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As _
    46.     Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
    47.      
    48.     Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _
    49.     ByVal uExitCode As Long) As Long
    50.      
    51.        Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
    52.           lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
    53.           lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
    54.           ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
    55.           ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
    56.           lpStartupInfo As STARTUPINFO, lpProcessInformation As _
    57.           PROCESS_INFORMATION) As Long
    58.      
    59.        Private Declare Function CloseHandle Lib "kernel32" _
    60.           (ByVal hObject As Long) As Long
    61.      
    62.        Private Declare Function GetExitCodeProcess Lib "kernel32" _
    63.           (ByVal hProcess As Long, lpExitCode As Long) As Long
    64.      
    65.        Private Const NORMAL_PRIORITY_CLASS = &H20&
    66.        Private Const INFINITE = -1&
    67.           Dim proc As PROCESS_INFORMATION
    68.           Dim start As STARTUPINFO
    69.      
    70.      
    71.        Public Function ExecCmd(cmdline$)
    72.        
    73.           ' Initialize the STARTUPINFO structure:
    74.           start.cb = Len(start)
    75.      
    76.           ' Start the shelled application:
    77.           ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
    78.              NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
    79.      
    80.           ' Wait for the shelled application to finish:
    81.              ret& = WaitForSingleObject(proc.hProcess, INFINITE)
    82.              Call GetExitCodeProcess(proc.hProcess, ret&)
    83.              Call CloseHandle(proc.hThread)
    84.              Call CloseHandle(proc.hProcess)
    85.              ExecCmd = ret&
    86.        End Function
    87.      
    88.        Sub Form_Click()
    89.           Dim retval As Long
    90.             Dim lngResult As Long
    91.         Dim lngReturnValue As Long
    92.        
    93.         'Replace the path and app.name.type with that of the application you want to use
    94.           retval = ExecCmd("C:\Users\User\Desktop\Project.exe")
    95.             lngReturnValue = SendMessageTimeout(retval, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG And SMTO_BLOCK, 1000, lngResult)
    96.         DoEvents
    97.          'u can give a tool tip text here
    98.         nid.szTip = "" & vbNullChar
    99.           nid.cbSize = Len(nid)
    100.         nid.hwnd = retval
    101.         nid.uId = vbNull
    102.         nid.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    103.         nid.uCallBackMessage = WM_MOUSEMOVE
    104.         nid.hIcon = Me.Icon
    105.         If lngReturnValue Then
    106.             MsgBox ("Responding")
    107.         Else
    108.             Shell_NotifyIcon NIM_DELETE, nid
    109.         'Close the host and the client if the client does not respond
    110.             Call GetExitCodeProcess(proc.hProcess, ret&)
    111.             Call CloseHandle(proc.hThread)
    112.             Call CloseHandle(proc.hProcess)
    113.            Unload Me
    114.         End If
    115.        End Sub

    module code
    vb Code:
    1. Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
    2. 'declaration for putting the application to system tray
    3. Public Type NOTIFYICONDATA
    4.     cbSize As Long
    5.     hwnd As Long
    6.     uId As Long
    7.     uFlags As Long
    8.     uCallBackMessage As Long
    9.     hIcon As Long
    10.     szTip As String * 64
    11. End Type
    12.  
    13.     'declare constants
    14. Public Const NIM_ADD = &H0
    15. Public Const NIM_MODIFY = &H1
    16. Public Const NIM_DELETE = &H2
    17. Public Const WM_MOUSEMOVE = &H200
    18. Public Const NIF_MESSAGE = &H1
    19. Public Const NIF_ICON = &H2
    20. Public Const NIF_TIP = &H4
    21. 'Dimension a variable as the user-defined data type.
    22. Public nid As NOTIFYICONDATA

    Change

    "C:\Users\User\Desktop\Project.exe"

    to match that of your system and the external program.

    Edit:

    I posted the original code in the Detect if program is not responding! thread.
    Last edited by Nightwalker83; Sep 27th, 2013 at 09:23 PM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Re: refresh tray icon

    I replaced the program but each time I launch the code, the window freezes.

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