G
Guest
i have a solution to gather the text in each window that is open, but would
rather use only managed code rather than unmanaged code my current solution
relies on. The purpose is to get the text in each open window
even/especially for child windows in other non managed mdi apps - if excel
has 3 books open or any other mdi app has several windows open, I'd like the
complete text from each window.
The current solution gives me more info than i need (quite a bit), as i'm
getting not just the text from each open window - i'm getting other stuff
that i am not familiar with with my desired info. heres the code i'm using
currently:
# Windows Form Designer generated code #
Private Delegate Function EnumWindowsProc( _
ByVal hwnd As IntPtr, ByVal lParam As Int32) As Int32
Private Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Int32) As Int32
Private Declare Function GetWindowTextLength Lib _
"user32.dll" Alias "GetWindowTextLengthA" _
(ByVal hwnd As IntPtr) As Int32
Private Declare Function GetWindowText Lib "user32.dll" Alias
"GetWindowTextA" _
(ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Int32) As Int32
Private Function EnumWindowsCallBack(ByVal hwnd As IntPtr, ByVal lParam As
Int32) As Int32
Dim sSave As String
sSave = Space(GetWindowTextLength(hwnd) + 1)
GetWindowText(hwnd, sSave, Len(sSave))
sSave = Microsoft.VisualBasic.Left(sSave, Len(sSave) - 1)
If sSave.Trim <> "" Then
lv.Items.Add(sSave)
End If
Return 1
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
lv.Items.Clear()
EnumWindows(AddressOf EnumWindowsCallBack, 0)
End Sub
Either a manged only alternative(perfect), a change to make to get only the
window text and not everythign else (a close second) or direction to go look
further (always appreciated) would be nice.
gabe
rather use only managed code rather than unmanaged code my current solution
relies on. The purpose is to get the text in each open window
even/especially for child windows in other non managed mdi apps - if excel
has 3 books open or any other mdi app has several windows open, I'd like the
complete text from each window.
The current solution gives me more info than i need (quite a bit), as i'm
getting not just the text from each open window - i'm getting other stuff
that i am not familiar with with my desired info. heres the code i'm using
currently:
# Windows Form Designer generated code #
Private Delegate Function EnumWindowsProc( _
ByVal hwnd As IntPtr, ByVal lParam As Int32) As Int32
Private Declare Function EnumWindows Lib "user32.dll" _
(ByVal lpEnumFunc As EnumWindowsProc, ByVal lParam As Int32) As Int32
Private Declare Function GetWindowTextLength Lib _
"user32.dll" Alias "GetWindowTextLengthA" _
(ByVal hwnd As IntPtr) As Int32
Private Declare Function GetWindowText Lib "user32.dll" Alias
"GetWindowTextA" _
(ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Int32) As Int32
Private Function EnumWindowsCallBack(ByVal hwnd As IntPtr, ByVal lParam As
Int32) As Int32
Dim sSave As String
sSave = Space(GetWindowTextLength(hwnd) + 1)
GetWindowText(hwnd, sSave, Len(sSave))
sSave = Microsoft.VisualBasic.Left(sSave, Len(sSave) - 1)
If sSave.Trim <> "" Then
lv.Items.Add(sSave)
End If
Return 1
End Function
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
lv.Items.Clear()
EnumWindows(AddressOf EnumWindowsCallBack, 0)
End Sub
Either a manged only alternative(perfect), a change to make to get only the
window text and not everythign else (a close second) or direction to go look
further (always appreciated) would be nice.
gabe