Solved

finding active window caption

Posted on 2001-06-14
2
245 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 40 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access 2013 combo box not working 3 73
Problem to With line 4 85
VBA Replace Function - What am I missing? 3 47
SQL Server 2012 to SQL Server 2016 24 50
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

738 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