Getting the window title/caption from handle id

Pixelscope

New Member
Joined
Mar 31, 2013
Messages
5
I'm trying to find an answer to fetching the lpWindowName from a handle. I already have a way of finding the correct handle, and there's no problem finding an answer to that, but how do I get the window title from a handle i.e. 66340?

Code:
FindWindow("SunAwtFrame", "(FTJ)")
Gets the handle.

Code:
Option Explicit
 
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Is the function.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
[SOLVED] Re: Getting the window title/caption from handle id


Hey, that worked great! Thanks a lot. The finished code looks like this:
Code:
    Dim wnd As Long, wtl As Long
    Dim winText As String
    wnd = FindWindow("SunAwtFrame", vbNullString)
    
    wtl = GetWindowTextLength(wnd)
    winText = Space$(wtl)
    GetWindowText wnd, winText, wtl + 1
    
    MsgBox winText
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,250
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top