I have开发者_C百科 an Internet Explorer page opend on my desktop. The name of the webpage is TEST. With FindWindow() from user32.dll i can get a handler over the window. In this page I have a button called Go and I 2 textboxes called Name and Surname. How can I write in thewebpage my name and surname and than click Go programatically? THX
The normal approach to updating foreign windows (WM_SETTEXT
et al) won't work because the form components within IE are not stock windows, rather they are rendered by IE itself.
To manipulate them you need to call via the DOM (or use something like WaitN).
using mshtml; //.net ref microsoft.mshtml
using SHDocVw; //com ref `microsoft internet controls` + change ref to no embed interop
int HWND = 0x001C0C10; //your IE
foreach(InternetExplorer ie in new ShellWindowsClass()) {
//find the instance
if (ie.HWND == HWND) {
//get doc
HTMLDocument doc = (HTMLDocument)ie.Document;
doc.getElementsByName("name").item(0).value = "bob";
doc.getElementsByName("surname").item(0).value = "smith";
doc.getElementsByName("go").item(0).click();
}
}
I am not sure what your asking is actually possible with Using Win32 (user32.dll), having said that If your trying to interact with the web server then you could simply use httprequest and httpresponse class to GET and POST variables as required.
HttpWebRequest testRequest = (HttpWebRequest)WebRequest.Create("http://.....");
HttpWebResponse testResponse = (HttpWebResponse)testRequest.GetResponse();
string responseStatus = testResponse.StatusCode.ToString();
testResponse.Close();
http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.aspx
If your tring to test or reply a standard set of event then you may want to have a look at Fiddler
http://www.fiddler2.com/fiddler2/
精彩评论