Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the caption of an active window 1

Status
Not open for further replies.

Pete222

Programmer
Joined
Dec 29, 2002
Messages
85
Location
GB
How do I retreve the caption on an active window of any program into a label i.e. Microsoft Word would be:
'Microsoft Word - Document 1'

Pete.
My site: clix.to/F
 
use GetForeGroundWindow Api to retrieve handle of active window. and use getWindowText for caption.
See this example code

Public Declare Function GetForegroundWindow Lib "user32" () As Long

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Function getWindCaption() As String
Dim strCaption As String
'Create a buffer
strCaption = String(250, Chr$(0))
'Get the windowtext
Dim cW As Long
cW = GetForegroundWindow
If cW > 0 Then
GetWindowText cW, strCaption, 250
strCaption = Left$(strCaption, InStr(strCaption, Chr$(0)) - 1)
getWindCaption = strCaption
End If
End Function

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top