• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

finding active window caption

i want to find the active title bar caption from my application created using vb 6.0 ,my application is in the systray. it has to find the caption of the other applications window, when they made as active windows. how can i do that?. please help me out.

Advance thanks
0
sanker
Asked:
sanker
1 Solution
 
sharmonCommented:
Copy this to a module and call it to get the foreground windows caption...but as soon as you click your application, it will become the foreground window...


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

Public Function GetFGWindowCaption() As String
  Dim lngHwnd As Long
  Dim lngRet As Long
  Dim strCaption As String
 
  lngHwnd = GetForegroundWindow()
 
  If lngHwnd <> 0 Then
    strCaption = Space$(255)
    lngRet = GetWindowText(lngHwnd, strCaption, 255)
   
    If lngRet <> 0 Then
      strCaption = Left$(strCaption, lngRet)
    End If
  End If
 
  GetFGWindowCaption = Trim$(strCaption)
End Function
0
 
sankerAuthor Commented:
hi sharmon

Thank u very much for helping me . The code u given  is very nice. earlier i tried with GetActiveWindow API.It doesn't helped me. Thank u once again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now