Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Active window
Message
 
 
General information
Forum:
Visual Basic
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00392623
Message ID:
00392780
Views:
10
>If you have a background app, how can you tell what the has the current focus? ie MyBackground app is running and I want to see what the user is currently 'in' before my background app moves to the front/top.

You can use the GetForegroundWindow and GetWindowText API calls. Sample:
Private Declare Function GetForegroundWindow Lib "usre32" () 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 Sub Form_Load()
Dim hwnd As Long, llen As Long
Dim strTitle As String
strTitle = Space(255) & vbNullChar

hwnd = GetForegroundWindow()
llen = GetWindowText(hwnd, strTitle, 255&)

If llen > 0 Then
   strTitle = Left$(strTitle,llen)
   ' do what you want here based on window title
Else
   ' error in getting window text
End If

End Sub
HTH.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform