Solved

finding active window caption

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Saving history changes to sub form 4 42
Using "ScreenUpdating" 6 64
vb6 connector to mongodb 2 83
clicking a shape in a frame array vb6 3 45
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…

770 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