Results 1 to 3 of 3

Thread: Text in a Window

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Lightbulb

    Can I pickup the contents of a window (external to my application)? I am able to get the handle of the correct window so how can I acheive my final objecvtive?


    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  2. #2
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Exclamation Specifications?

    You aren't specific, so I'll give you a general example of how to get text from Notepad and putting it into a Multiline TextBox, Text1 when you click a button, Command1.
    Code:
    Option Explicit
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    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 Const WM_GETTEXT = &HD
    Private Const WM_GETTEXTLENGTH = &HE
    
    Private Sub Command1_Click()
        Dim sBuffer As String, lLength As Long, hWndNotepad As Long
        
        ' Find the Notepad Window handle
        hWndNotepad = FindWindowEx(0, 0, "Notepad", vbNullString)
        ' Find the Notepad Edit (TextBox) handle
        hWndNotepad = FindWindowEx(hWndNotepad, 0, "Edit", vbNullString)
        
        ' Get the length of the text in the Edit
        lLength = SendMessage(hWndNotepad, WM_GETTEXTLENGTH, 0, ByVal 0)
        ' Add 1 for the null-terminator
        lLength = lLength + 1
        
        ' Make room in the receiving string - it will be filled with Nulls
        sBuffer = String(lLength, vbNullChar)
        
        ' Receive the string
        Call SendMessage(hWndNotepad, WM_GETTEXT, lLength, ByVal sBuffer)
        
        ' Put it in the TextBox
        Text1.Text = sBuffer
        
        '
        ' Note: If you are feeling advanced, you can use smaller code!
        '
        ' Dim sBuffer As String, hWndNotepad As Long
        '
        ' hWndNotepad = FindWindowEx(FindWindowEx(0, 0, "Notepad", vbNullString), 0, "Edit", vbNullString)
        ' sBuffer = String(SendMessage(hWndNotepad, WM_GETTEXTLENGTH, 0, ByVal 0) + 1, vbNullChar)
        ' Call SendMessage(hWndNotepad, WM_GETTEXT, Len(sBuffer), ByVal sBuffer)
        ' Text1.Text = sBuffer
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Talking More Specific

    Sorry!

    I have shelled out to MakeCab.EXE. I am looping the EnumWindows and using GetWindowText until the MakeCab window is gone. This works fine. What I would like to do is get the text within the DOS window (it has a % complete figure I'd like to use) and present it to the user.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



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