2011-05-11 42 views
1

我的桌面上有一個Internet Explorer頁面打開。網頁的名稱是TEST。使用user32.dll中的FindWindow(),我可以在窗口中獲得一個處理程序。在這個頁面中,我有一個名爲Go和I 2的文本框,名爲Name和Surname。我怎樣才能在網頁上寫我的名字和姓氏,然後點擊Go進行編程? THXInternet Explorer頁面上的SendMessage user32dll

回答

0

我不確定你使用Win32(user32.dll)實際上可能會問什麼,說 如果你試圖與web服務器交互,那麼你可以簡單地使用httprequest和httpresponse類來GET和POST根據需要變量。

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 

如果你的字符串進行測試或答辯一套標準的事件,那麼你可能想看看提琴手

http://www.fiddler2.com/fiddler2/ 
2

正常的方法來更新外國的窗口(WM_SETTEXT等)榮獲」因爲IE中的表單組件不是股票窗口,而是它們由IE自身呈現。

要操縱它們,您需要通過DOM調用(或使用類似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(); 
    } 
} 
相關問題