Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

finding active window caption

Posted on 2001-06-14
2
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
sharmon earned 160 total points
ID: 6189899
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
ID: 6198162
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

618 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