I want to check if an icon exists in the systray; as in, if "X" application has displayed their systray icon in the systray area.
I've Googled for information about how to do this but I didn't find anything.
UPDATE :
This what I've tried in VB.NET translating the C# examples of the url gived by Robert comment, but I don't know how to continue it.
Imports System.Runtime.InteropServices
Public Class Form1
Public Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As IntPtr, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Public Shared Function WindowHandle(sTitle As String) As Long
Return FindWindow(vbNullString, sTitle)
End Function
Private Shared Function GetSystemTrayHandle() As IntPtr
Dim hWndTray As IntPtr = FindWindow("Shell_TrayWnd", Nothing)
If hWndTray <> IntPtr.Zero Then
hWndTray = FindWindowEx(hWndTray, IntPtr.Zero, "TrayNotifyWnd", Nothing)
If hWndTray <> IntPtr.Zero Then
hWndTray = FindWindowEx(hWndTray, IntPtr.Zero, "SysPager", Nothing)
If hWndTray <> IntPtr.Zero Then
hWndTray = FindWindowEx(hWndTray, IntPtr.Zero, "ToolbarWindow32", Nothing)
Return hWndTray
End If
End If
End If
Return IntPtr.Zero
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox(WindowHandle("Steam")) ' 6687230
MsgBox(GetSystemTrayHandle()) ' 62789
End Sub
End Class
Note: Icons in the system tray only appear when their corresponding apps are running. If you still don’t see icons on your system tray, use the Turn system icons on or off setting and see if it helps. To do this, right-click the Taskbar > Taskbar Settings. In the Taskbar Settings, go to the Notification area and select Turn system icons on or off.
The easiest way to hide an icon that you don’t want to see in the System Tray is to reverse the previous section's process. Click and hold an icon in the System Tray. Drag the icon to the ^ icon. Position the icon where you want it in the expanded System Tray. Release the left mouse button.
Click and hold an icon from the expanded System Tray. Drag the icon into the standard System Tray. Release the left mouse button. If you don’t like the positioning of the icon, you can click and drag it left or right to position it where you want it in the tray.
Go to the Notification area section from the Taskbar settings again and click or tap the "Turn system icons on or off" link. Access Turn system icons on or off Choose which system icons are enabled by turning on the switch next to them. Turn On the system icons that you want to enable
You should read this code-project article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With