How to get the title of currently active window

This is a simple function that can be used to get the title of other windows, especially useful to get title of currently active window.
THIS CODE IS MEANT FOR VB6 ONLY. FOR VB.NET, SEE THIS POST

Code :

Usage:

You can get the title of currently active window by invoking GetWindowTitle method:

Happy coding!

2 comments

  1. Dim l As Long
    Dim s As String

    l = GetWindowTextLength(hwnd)
    s = Space(CInt(l + 1))

    GetWindowText(hwnd, s, l + 5)

    GetWindowTitle = Microsoft.VisualBasic.Left$(s, l)

    Your code wasn’t showing the form names properly. I fixed it

Leave a Reply

Your email address will not be published. Required fields are marked *