Imports DD_LIB_Standards Public Class clsWINDOWSApi Private Declare Function GetForegroundWindow Lib "user32.dll" Alias "GetForegroundWindow" () As IntPtr Private Declare Auto Function GetWindowText Lib "user32.dll" (ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef lpdwProcessID As Integer) As Integer Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As IntPtr, ByVal WinTitle As String, ByVal MaxLength As Integer) As Integer Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Int32) As Integer Private Shared Function GetClassName(ByVal hWnd As System.IntPtr, _ ByVal lpClassName As System.Text.StringBuilder, _ ByVal nMaxCount As Integer) As Integer ' Leave function empty End Function Public Shared Function GetCaption() As String Dim Caption As New System.Text.StringBuilder(256) Dim hWnd As IntPtr = GetForegroundWindow() Dim pid As Integer = 0 GetWindowThreadProcessId(hWnd, pid) If pid = 0 Then Exit Function Return Caption.ToString() End Function Public Shared Function IsRelevantWindow(windowname As String) Try Dim enumerator1 As New clsWindowApi 'Jedes Formularwindow durchlaufen For Each top As clsWindowApi.ApiWindow In enumerator1.GetTopLevelWindows() If LogErrorsOnly = False Then clsLogger.Add(" ... top-window Name: " & top.MainWindowTitle, False) If top.MainWindowTitle.Contains(windowname) Or top.MainWindowTitle.ToLower = windowname.ToLower Then Console.WriteLine(top.MainWindowTitle) Return False End If Next top Catch ex As Exception MsgBox("Error in IsRelevantWindowt:" & vbNewLine & ex.Message, MsgBoxStyle.Critical) clsLogger.Add(">> Error in IsRelevantWindow:" & ex.Message, False) Return False End Try End Function Private Shared m_LastHwnd As Long Public Shared Sub Get_ForegroundWindow_Info() '—– Get the Handle to the Current Forground Window —– Dim hWnd As IntPtr = GetForegroundWindow() If hWnd = IntPtr.Zero Then Exit Sub '—– Find the Length of the Window’s Title —– Dim TitleLength As Int32 TitleLength = GetWindowTextLength(hWnd) '—– Find the Window’s Title —– Dim WindowTitle As String = StrDup(TitleLength + 1, "*") GetWindowText(hWnd, WindowTitle, TitleLength + 1) '—– Find the PID of the Application that Owns the Window —– Dim pid As Integer = 0 GetWindowThreadProcessId(hWnd, pid) If pid = 0 Then Exit Sub '—– Get the actual PROCESS from the process ID —– Dim proc As Process = Process.GetProcessById(pid) If proc Is Nothing Then Exit Sub Dim msg = pid.ToString & vbNewLine PROC_PID = pid.ToString PROC_Name = proc.ProcessName msg &= vbNewLine & "Procname: " & proc.ProcessName msg &= vbNewLine & "MainWindowTitle: " & proc.MainWindowTitle msg &= vbNewLine & "WindowTitle: " & WindowTitle PROC_WindowTitle = WindowTitle msg &= vbNewLine & TitleLength.ToString ' MsgBox(msg) End Sub End Class