How to access WebBrowser in Internet Explorer

Source: Internet
Author: User

[Delphi] How to access WebBrowser in Internet Explorer [Repost 2009-12-30 19:10:38]

size: big medium small

Here's an example that shows how to get the HTML source for its page elements from an open Internet Explorer:


Const
Rspsimpleservice = 1;
Rspunregisterservice = 0;

Type
Tobjectfromlresult= function (lresult:lresult; const IID:TIID; Wparam:wparam; Out pobject): HRESULT; stdcall;

function Getiefromhwnd (Whandle:hwnd; var ie:iwebbrowser2): HRESULT;
Var
Hinst:hwnd;
lres:cardinal;
Msg:integer;
Pdoc:ihtmldocument2;
Objectfromlresult:Tobjectfromlresult;
Begin
HInst: = LoadLibrary (' Oleacc.dll ');
@ObjectFromLresult: = GetProcAddress (HInst, ' objectfromlresult ');
If @ObjectFromLresult <> Nil Then
Begin
Try
MSG: = RegisterWindowMessage (' Wm_html_getobject ');
SendMessageTimeout (WHANDLE, MSG, 0, 0, Smto_abortifhung, lres);
Result: = Objectfromlresult (lres, IHTMLDocument2, 0, PDOC);
If Result = S_OK Then
(Pdoc.parentwindow as IServiceProvider). QueryService (IWebBrowserApp, IWebbrowser2, IE);
Finally
FreeLibrary (HInst);
End
End
End

Procedure Tform1.button1click (Sender:tobject);
Var
All:ihtmlelementcollection;
Htmlelement:ihtmlelement;
I:integer;
Document:ihtmldocument2;
Ie:iwebbrowser2;
Wnd:hwnd;
Wndchild:hwnd;
Begin
Wnd: = FindWindow (' IEFrame ', nil);
If Wnd = 0 Then
Begin
Messagedlg (' No Running instance of the Internet explorer! ', Mterror, [Mbok], 0);
End
Walk Shell DocObject view->internet explorer_server
Wndchild: = FindWindowEx (Wnd, 0, ' Shell docobject View ', nil);
If Wndchild <> 0 Then
Begin
Wndchild: = FindWindowEx (wndchild, 0, ' Internet explorer_server ', nil);
If Wndchild <> 0 Then
Begin
Getiefromhwnd (Wndchild, IE); Get Iwebbrowser2 from Handle
Document: = IE. Document as IHtmlDocument2;
If Assigned (Document) Then
Begin
All: = document.all;
For I: = 0 to All.length-1 do
Begin
HtmlElement: = All.item (i, 0) as IhtmlElement;
SOURCEVIEW.LINES.ADD (IntToStr (i) + "+ htmlelement.innerhtml);
End
End
End
End
End


uses MSHTML,ActiveX


Tiid could be Tguid .


Wndchild: = FindWindowEx (Wnd, 0, ' Shell docobject View ', nil);
This sentence can not get the handle under the IE7?
Did anyone get an example of the handle to Shell DocObject View under IE7?


The following is a testcomplete script, see IE 7 more than a tabwindowclass, you should know how to do it! 

p = sys.waitprocess ("IExplore ");  
W = P.waitwindow (" IEFrame "," * ",-1);  
if (! w.exists)  
P = sys.waitprocess ("explorer");  
//IE should be running now... 
if (p.exists) {& nbsp
W = P.window ("IEFrame", "*", 1);  
//Give IE 3 seconds to start, check for the IE7 tabwindowclass first...  ;
if (W.waitwindow ("Tabwindowclass", "*",-1, 3000). Exists)  
ie = W.window ("Tabwindowclass", "*"). Window ("Shell docobject View"). Window ("Internet explorer_server", "" ", 1);  
else 
ie = W.window (" Shell docobject View "). Window ("Internet explorer_server", "", 1);  
page = ie. Page ("*");  


Thank you very much icebird, I am in
Wndchild: = FindWindowEx (Wnd, 0, ' Shell docobject View ', nil);
A line of code was added earlier,
Wndtab: = FindWindowEx (Wnd, 0, ' Tabwindowclass ', nil);
You can get the handle under IE7.


How to access WebBrowser in Internet Explorer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.