7

システムトレイにアイコンが存在するかどうかを確認したい。たとえば、「X」アプリケーションが systray 領域に systray アイコンを表示した場合。

これを行う方法に関する情報をグーグルで検索しましたが、何も見つかりませんでした。

アップデート :

これは、Robert のコメントで指定された URL の C# の例を VB.NET で翻訳して試したものですが、続行する方法がわかりません。

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
4

1 に答える 1