Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27221

Get Active Window problem

$
0
0
Hi, I'm trying to make my program get the active window title and save it as a string.

I want this to find the title of the active window, save it to a string, and to get the next active window.

Here is the code so far:

Code:

    Private Declare Function GetForegroundWindow Lib "user32.dll" () As Int32
    Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
    Private LastCheckedForegroundTitle As String = "" 'Title of the foreground window when last checked

    'Gets the title of the active window
    Private Function GetActiveWindowTitle() As String
        Dim MyStr As String
        MyStr = New String(Chr(0), 100)
        GetWindowText(GetForegroundWindow, MyStr, 100)
        MyStr = MyStr.Substring(0, InStr(MyStr, Chr(0)) - 1)
        Return MyStr
        TextBox1.Text = TextBox1.Text + MyStr
    End Function

If you need more info, please let me know. Thanks.

Viewing all articles
Browse latest Browse all 27221

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>