Results 1 to 4 of 4

Thread: GetWindowText... I wish

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    GetWindowText... I wish

    I am trying to use the GetWindowText API call in order to retrieve the caption that appears in the spy++ window. It is returning no value. I am using this syntax GetWindowText orig, caption, 100. I have tried sending both of the last parameters byval. I noticed I am incapable of getting wm_gettext to work correctly as well. I always get a null string. Orig is a long, caption is a string. Any help woudl be much appreciated. Thank you very much.

    Joe

  2. #2
    DerFarm
    Guest
    if what you really want is the title of the window, this will work:

    It was pretty much stolen from the friendly folks at KDP
    http://www.allapi.net/


    you send it a unique PART of the string. if you send it something
    that is contained in 2 open windows, you get the first one it
    encounters.

    Code:
    Function WindowTitle(Optional appTitle As String, _
                           Optional apphandle As Long) As String
    '   This function will return the Application Title and AppHandle
    '       as a delimited string:  "This is the title|1234"
    
        Dim dummyVariable As Long, Ret_Handle As Long
        Dim lenTitle As Integer, Ret_Val As String
        Dim WinTitle As String * 255
    
    
        Ret_Val = ""
        If appTitle = "" And apphandle = 0 Then GoTo Xit_WindowTitle
            
        WinTitle = String(255, Chr$(0))
        If appTitle > "" Then  'A title or partial title was passed.  Search
           apphandle = GetTopWindow(0)
           Do Until apphandle = 0
               dummyVariable = GetWindowText(apphandle, WinTitle, 255)
               If InStr(WinTitle, appTitle) Then
                  Ret_Handle = apphandle
                  apphandle = 0
               End If
               apphandle = GetWindow(apphandle, GW_HWNDNEXT)
           Loop
        Else     'No title.  Must be appHandle
           dummyVariable = GetWindowText(apphandle, WinTitle, 255)
           Ret_Handle = apphandle
        End If
        Ret_Val = Left$(WinTitle, InStr(WinTitle, Chr$(0)) - 1) & _
                  "|" & _
                  LTrim$(Str$(Ret_Handle))
         
    Xit_WindowTitle:
        WindowTitle = Ret_Val
    End Function
    it requires:
    Private Declare Function GetWindowText Lib "user32"
    Alias "GetWindowTextA"




    HTH

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Posts
    352

    Not exactly what I am looking for...

    I am trying to obtain the caption that spy++ retrieves when you use select a window. This caption does not have to be of a "window" persay. It can obtain the caption of a button, a picture, etc. Thank you for the suggestion, but that will not work for what i need.

    Joe

  4. #4
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

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