Solved

finding active window caption

Posted on 2001-06-14
2
240 Views
Last Modified: 2010-05-02
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
Comment
Question by:sanker
2 Comments
 
LVL 6

Accepted Solution

by:
sharmon earned 40 total points
Comment Utility
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
 

Author Comment

by:sanker
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now