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?
Printable View
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?
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
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.