Question SendMessage

Taien

Member
Joined
Oct 8, 2008
Messages
9
Programming Experience
1-3
I'm trying to teach myself to use SendMessage to manipulate other windows and have been reading as much as possible on the net to understand how to do this. I've come upon a problem though that I have been unable to find an answer for on the net. Currently I'm attempting to read text from another window. I am under the impression that I use FindWindowEx to dig into a target window's handle and find the controls in the form, although I still haven't been able to do it successfully. I read somewhere that I use Spy++ to find the names of the classes I am searching for with FindWindowEx, and that once I have the handle of the specific control containing the text I use SendMessage to send it a WM_GETTEXT message. The problem I'm having is that for the lParam MSDN says that SendMessage needs a "Buffer", and I'm not sure how to use one of those. I tried using the type Buffer, but that didn't seem to work. Is buffer a euphamism for a certain variable type? I tried using IntPtr as well but the returned IntPtr was always IntPtr.Zero...

So basically my questions are:

1. How exactly can I use FindWindowEx to locate a control's handle? I'm having trouble getting it to work, but I'm probably just not understanding how it functions.

2. What is the variable type for the "buffer" required in lParam of the WM_GETTEXT SendMessage?
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,349
Location
Sydney, Australia
Programming Experience
10+

Taien

Member
Joined
Oct 8, 2008
Messages
9
Programming Experience
1-3
I have a follow-up question....is there a way to enumerate results to FindWindowEx or to ignore previously returned handles on following searches? I have a section where I'm digging into the handles for a window and I come to a spot where two controls have the same class name. I'm assuming FindWindowEx always returns the same one (maybe the lowest intptr value?) so I'm hoping there's a way to check multiple results.
 

Taien

Member
Joined
Oct 8, 2008
Messages
9
Programming Experience
1-3
I have a new problem :) This whole time I've been constructing this sub to get text from Internet Explorer, and now I find that Internet Explorer doesn't work with the normal method of finding handles for sendmessage. So I'm left to believe that the only way to get text from IE is to just have the program copy the text to clipboard with Ctrl+A and Ctrl+C and then parse it from there? I can't seem to locate anything on how to WM_GETTEXT from IE. I managed finally to successfully find a child handle I wanted deep in the tree for internet explorer, but when I hit it with a WM_GETTEXT it returns nothing. Argh! And I know I'm using gettext right because it works fine on other controls in the window :) If anyone knows a way to make this work, please respond :)
 

Taien

Member
Joined
Oct 8, 2008
Messages
9
Programming Experience
1-3
Well, I'm just trying to copy text, so really, using the source html might work. I hadn't considered that. Is there a way to do that?

Preferably though I'd like to be able to capture text that changes, such as activex webpages and java apps and such. The page I'm using to build this is a facebook game that shows up as a "MacromediaFlashPlayerActiveX" control. It returns no text when WM_GETTEXT'ed. I may end up just making the app copy all to clipboard though...would be the most up-to-date and accurate method...just bulky in its operation :( (Having selected text, etc)
 

freqsounds

Member
Joined
Dec 29, 2010
Messages
5
Programming Experience
1-3
The best way to get the html is to bind to IE. There's some examples in some other forums on how to bind to existing (open) browsers, or create a new instance.

Once you have a handle on it, you can click links and buttons, insert text in text boxes, and get the source of the document. IE can be fully automated.

I haven't played with WM_GETTEXT, so I'm not sure where/when to use it.

If it's a webpage, and the element has an ID or Name, then I would just bind to IE and pull the source and manipulate it that way.

Just a tip, you can use a timer to call a sub that will consistantly update your source html (innerHTML) variable. it's a lot cleaner than putting it all in the clipboard. Make sure you reference the Microsoft Internet Controls... Something like:

Imports SHDocVw

Public Class Form1


Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
Dim msie As New InternetExplorer
msie.Visible = True
msie.Navigate("www.google.com")
Do While msie.Busy
Threading.Thread.Sleep(100)
Loop
msie.Document.getelementbyid("q").value = "VB.Net"
msie.Document.getelementbyid("btnG").Click()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


End Sub
End Class
 
Top Bottom