|
-
Jun 4th, 2001, 09:31 PM
#1
Thread Starter
New Member
title of the window in focus
I am looking for a way to get the title of the window currently in focus. I should know how to do this but I've been coding forever and it's late.
I hope someone can help, thanks
 ~* Sp1Ral FlAmE *~ & Intrix Software 
-
Jun 4th, 2001, 09:58 PM
#2
Registered User
To get the caption of a window:
sWindowText = String(255, Chr(0))
SendMessageByStr hWnd, WM_GETTEXT, 255, sWindowText
sWindowText = Left(sWindowText, InStr(1, sWindowText, Chr(0), vbTextCompare) - 1)]
To get window current window:
GetForegroundWindow()
I assume you don't need the declarations.
-
Jun 4th, 2001, 11:12 PM
#3
Try this:
Code:
Private Declare Function GetForegroundWindow _
Lib "user32" () As Long
Private Declare Function GetWindowTextLength _
Lib "user32" Alias "GetWindowTextLengthA" (ByVal _
hwnd As Long) 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 GetParent Lib "user32" (ByVal _
hwnd As Long) As Long
Private Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
Dim i As Long
Dim j As Long
i = GetForegroundWindow
If ReturnParent Then
Do While i <> 0
j = i
i = GetParent(i)
Loop
i = j
End If
GetActiveWindowTitle = GetWindowTitle(i)
End Function
Private Function GetWindowTitle(ByVal hwnd As Long) As String
Dim l As Long
Dim s As String
l = GetWindowTextLength(hwnd)
s = Space(l + 1)
GetWindowText hwnd, s, l + 1
GetWindowTitle = Left$(s, l)
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|