I am using a EM_GETTEXTLENGTHEX, the SendMessage() and EnumChildWindows function to retrieve the text that is displayed in other windows.
The combination of these results in me being able to perfectly well retrieve the text from the current form that I have created in Visual Basic, as well as text from some other applications, such as Notepad.
However, these calls do not work when I try and retrieve the text from some other applications, for example Windows Live Messenger, Word, Internet Explorer or Firefox.
This leads me to believe that the way I am retrieving and using the hWnd's from EnumChildWindows is incorrect or I am missing a vital part of code.
At the moment, if I were to use EnumChildWindows to retrieve the child hWnd's from say, Word or Live Messenger, I would have several hWnd's returned, but none of them have any textual response from SendMessage() with the EM_GETTEXTLENGTHEX param.
My question is, looking at the code below, should I be using something other than EnumChildWindows and/or does EnumChildWindows return the children of the children of the original hWnd, or just the children of the hWnd I passed it originally? If the answer to the latter is that it only passes me the children of the hWnd, how would I go about retrieving the children of those children? (If that makes any sense what-so-ever.)
ps. My apologies for the absolutely dreadful code, unfortunately it's messy because it I'm trying to make it work, not make it look pretty (yet!)
TextBox4.Text = ""
Dim hWnd As IntPtr
hWnd = GetForegroundWindow()
// Calls to the TextBox4.Text are purely for seeing the result
// of each function during testing
TextBox4.Text = "hWnd = " + hWnd.ToString() + Environment.NewLine
EnumChildWindows(hWnd, AddressOf EnumChildProc, 0)
For i = 0 To UBound(lHwnd)
Dim hWnd22 As IntPtr
// hWnd22 is the child of hWnd
hWnd22 = lHwnd(i)
TextBox4.Text = TextBox4.Text + "Child hWnd = " + hWnd22.ToString() + Environment.NewLine
' StringBuilder SendMessage test
Dim sb As StringBuilder = New StringBuilder("", 512)
Dim tl As Integer = SendMessage(hWnd22, WM_GETTEXTLENGTH, vbNull, sb)
Dim t As New String(" ", tl + 512)
// This is the call that retrieve the text from the hWnd
tl = SendMessage(hWnd22, EM_GETTEXTLENGTHEX, 5120, sb)
TextBox4.Text = TextBox4.Text + "STRING = " + sb.ToString() + Environment.NewLine + Environment.NewLine