PDA

Click to See Complete Forum and Search --> : API - find window name based off hWnd #


jonesj
Jan 18th, 2000, 01:47 AM
This may be an easy question. If I have a hWnd, what declare do I use to grab the windows name property? I've accomplished the reverse, type in the name of a window and have it return it's number (using FindWindow), but I want to fill in a list box of these using their names, not numbers. I'm VERY new at this, so the more info, the better. Thanks!!

Aaron Young
Jan 18th, 2000, 02:05 AM
Use the GetWindowText() API to return the Windows Caption, ie.

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

Function GetWindowCaption(ByVal lhWnd As Long) As String
Dim sCaption As String
sCaption = Space(255)
GetWindowCaption = Left$(sCaption, GetWindowText(lhWnd, ByVal sCaption, 255))
End Function

Usage:
sWindowCaption = GetWindowCaption(lTheHwnd)

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
ajyoung@pressenter.com

ZanM
Jan 18th, 2000, 10:53 AM
and if what you want isn't the windows text try GetClassName
here are two function one get the handle of a window the mouse is over the second usees the first to get the class name of the window the mouse is over
you'll need to add getcursorpos,pointapi,windowfrompoint,and getclassname for these functions to work

Public Function wHwndFromPoint() As Long
Dim point As POINTAPI, pointX As Long, pointY As Long
Dim Hndl As Long
Call GetCursorPos(point)
pointX& = point.X
pointY& = point.Y
Hndl& = WindowFromPoint(pointX&, pointY&)
If Hndl& <> 0& Then
wHwndFromPoint& = Hndl&
Else
wHwndFromPoint& = 0&
Exit Function
End If
End Function

Public Function wClassFromPoint() As String
Dim Hndl As Long, wClass As String * 100, w As String
Hndl& = wHwndFromPoint&
w$ = GetClassName(Hndl&, wClass$, 100)
wClassFromPoint$ = Left(wClass$, w$)
End Function


------------------
SomeTimes Coffee Just Isn't Enough.
Zan Magi