How to use sendmessage to send text to browser
I'm using vb6. How do I use sendmessage to send text to the microsoft internet controls component that's in my main form. I need to send text to a textbox that's in a webpage in the browser. Everything works flawlessly with sendkeys, however I really want to free up my computer to do other things. The webpage is also in XML.
Right now I can set the text of a textbox.
To prevent garbage text i used a modified sendmessage (change ByVal lParam As Any to ByVal lParam As String)
Code:
Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Code:
Call SendMessageByString(Frmmain.Text2.hwnd, WM_SETTEXT, 0&, "Hello")
The above code works
What I am trying to do is
Code:
Call SendMessageByString(Frmmain.browser.hwnd, WM_SETTEXT, 0&, "Hello")
The above code returns both an automation error and an unknown error in a single msgbox. I've tried wm_keydown / wm_keyup and it doesn't work for the textbox (I think I'm doing something wrong). Remember that the webpage is in XML. I think the problem is that a specific object like a textbox in the webpage needs to be pointed out, otherwise it sends text to the browser component which does nothing. Just like trying to send text to a picturebox does nothing. I know there's a command out there where you can enter in text to a certain object or element in the webpage but I forgot how to do it.
Code:
Frmmain.Browser.Document.All("Id of html element").SetAttribute("Value", "new value")
or
Code:
frmmain.Browser.Document.GetElementById("username").SetAttribute("Value", frmmain.txtuser.Text)
The above code seems to be in vb.net, is browser.document.all going to solve my problem?
Re: How to use sendmessage to send text to browser
Hai nesu,
This is an HTML DOM method. in my example, the code when run opens internet explore and place the word 'cricket' in gogle search and give you the results. check weather this can be apply to your project :)
Code:
Option Explicit
Private Sub Command1_Click()
Dim oIE As Object
Dim URL As String
Set oIE = CreateObject("InternetExplorer.Application")
URL = "http://www.google.com"
oIE.Visible = True
oIE.navigate (URL)
Do While oIE.readyState <> 4 And oIE.Busy
DoEvents
Loop
oIE.Document.All.Item("q").Value = "cricket"
oIE.Document.All.Item("btnG").Click
End Sub
here 'q' the text box name in the google home page where we type our queries.