I am writing on vb.net, interested in getting the name of the active window. An application can have several other windows open. Test_name is successfully obtained through:

For Each procs In Process.GetProcesses(".") Try Debug.Print(procs.MainWindowTitle) Catch End Try Next 

And how to get the names of open windows in the same application "Information about the store" and "Introduction events"?

enter image description here

  • one
    In WinApi, GetForegroundWindow and GetFocus functions were nick_n_a

1 answer 1

Thanks @nick_n_a for the tip, I found a good example that gets the title of the active window (in this case, "Store Information" and "Event Introduction"):

 <DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> Public Shared Function GetForegroundWindow() As IntPtr End Function <DllImport("user32.dll")> _ Private Shared Function GetWindowText(ByVal hWnd As Integer, ByVal text As StringBuilder, ByVal count As Integer) As Integer End Function Private Sub GetActiveWindow() Const nChars As Integer = 256 Dim handle As Integer = 0 Dim Buff As New StringBuilder(nChars) handle = GetForegroundWindow() If GetWindowText(handle, Buff, nChars) > 0 Then 'Выводит тайтл именно текущего активного окна, т.е. "Введение события" Debug.Print(Buff.ToString()) End If End Sub