I am trying to retreive text from another application by app’s control handle. I have no problem if control is “static” but my code seems not working for “edit” control. As MSDN says, GetWindowText cannot retreive text from EDIT control but maybe you know another way of achieving this?
My current code is here:
Dim newHwnd As IntPtr = Handler.GetClassByPosition(ParentHwnd, cls, classPosition)
Dim length As Integer = Handler.GetWindowTextLength(newHwnd)
Dim sb As New String(" ".Chars(0), length + 1)
If cls = "edit" Then
Handler.GetWindowText(newHwnd, sb, sb.Length)
End If
where GetClassByPosition returns control’s handle by specifying parent handle, class name (static,edit or button) and classPosition (used in loop – not important for now)
As I said, it works great with STATIC (labels etc) but it returns 0 if I’m retreiving text from EDIT (textbox) control of that external application.
UPDATE:
I have tried the following solution which success in returning data if data is integer but if it contains any letter, result is 0:
Dim tmpstr As IntPtr = Marshal.AllocHGlobal(100)
Dim NumText = API.SendMessage(Hwnd, API.WM_GETTEXT, 200, tmpstr )
NumText = Marshal.PtrToStringAnsi(tmpstr )
Return NumText
Thanks in advance,
Nikola
try this: