|
-
Apr 13th, 2001, 05:21 PM
#1
Thread Starter
Lively Member
Is there a way to find out the active application? The reason for this is I use the "AppActivate" method in VB, however I the application I activate is already active, my program freezes.
-
Apr 13th, 2001, 05:37 PM
#2
Use the GetForegroundWindow function.
Code:
Private Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
Private Sub Command1_Click
MsgBox "The handle of the active window is: " & GetForegroundWindow
End Sub
-
Apr 13th, 2001, 05:41 PM
#3
Thread Starter
Lively Member
How would you return the "title" of this window using the returned handle from the GetForegroundWindow?
-
Apr 13th, 2001, 05:43 PM
#4
Good Ol' Platypus
GetWindowText, I'm pretty sure, or GetWindowTitle.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation. 
(Just a heads-up)
-
Apr 13th, 2001, 08:12 PM
#5
Use this code.
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
|