Results 1 to 3 of 3

Thread: [VB6] How to get title of a window

Hybrid View

  1. #1

    Thread Starter
    Member LoopUntil's Avatar
    Join Date
    Jul 2008
    Posts
    58

    Question [VB6] How to get title of a window

    How can I get the title of a window where I'm writing in?

    (Example: I'm writing something in Notepad (so my program will MsgBox me the name of the window (notepad) , BUT not when I click with the mouse but only when I'm writing something)

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [VB6] How to get title of a window

    This should return the titlebar caption of the foreground window , if that helps?

    Code:
    Option Explicit
    
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal Hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal Hwnd As Long) As Long
    
    Public Function GetActiveTitle() As String
    ' // Return title bar caption of foreground program.//
        Dim Length As Long, CurrWnd As Long
        Dim sItem As String
        
        CurrWnd = GetForegroundWindow
        Length = GetWindowTextLength(CurrWnd)
        sItem = Space$(Length + 1)
        Length = GetWindowText(CurrWnd, sItem, Length + 1)
        GetActiveTitle = Mid(sItem, 1, Len(sItem) - 1)
    End Function
    Code:
    Private Sub Timer1_Timer()
        Text1 = GetActiveTitle
    End Sub

  3. #3

    Thread Starter
    Member LoopUntil's Avatar
    Join Date
    Jul 2008
    Posts
    58

    Re: [VB6] How to get title of a window

    Thanks again Edge, this code is quite helpful but mmm how can I get the title ONLY when someone writes something in that window? Or maybe when the window get focus...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width