Results 1 to 3 of 3

Thread: API - find window name based off hWnd #

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Fairfax, VA 22033
    Posts
    1

    Post

    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!!

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the GetWindowText() API to return the Windows Caption, ie.
    Code:
    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
    [email protected]
    [email protected]


  3. #3
    Addicted Member ZanM's Avatar
    Join Date
    Oct 1999
    Location
    The here and now.
    Posts
    191

    Post

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width