|
-
Dec 5th, 2001, 07:32 PM
#1
Getting Windows text via the API
I have been trying to figure out how to get the full name of a window to show up in a msgbox for quite some time. I am not sure how to grab the name of a window via user32 and have it popup in a msgbox in my program.
I have been trying to use showwindow and getwindowtext in order to do this. I am having problems poiting to a window OUTSIDE of my VB program. I can return the name of "form1" just fine, but I want the window name of a program totally outside my VB program.
Any suggestions would be greatly appreciated.
Thanks,
Zac
-
Dec 5th, 2001, 08:28 PM
#2
I tried the following code, but the problem is Clarify is only the first 7 characters of the title of the window. The full title of the window is "Clarify - ClearSupport - [Clarify U.S.] - SRX011204605600." I'm wondering if there is a way to check only the first 7 characters of a window ? I only need to find the first instance of the window and return the last 15 characters of the Window's title..... Any suggestions ?
Private Sub Command1_Click()
Dim hWnd As Long ' receives handle to the found window
Dim retval As Long ' generic return value
hWnd = FindWindow(vbNullString, "Clarify")
If hWnd = 0 Then
MsgBox "Clarify isn't running"
Else
retval = FlashWindow(hWnd, 1)
retval = FlashWindow(hWnd, 0)
End If
End Sub
-
Dec 6th, 2001, 07:34 AM
#3
Try this:
VB 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
'Posted by Matthew Gates 10/30/2001
-
Dec 6th, 2001, 01:39 PM
#4
Thanks, but I figured it out I appreciated the reply, though.
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
|