The following is an example of how to obtain the HTML of its webpage element from Internet Explorer.Source code:
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, 1000, 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 ('ieframework', nil );
If WND = 0 then
Begin
Messagedlg ('no running instance of Internet Explorer! ', Mterror, [mbok], 0 );
End;
// Walk shell docobject view-> Internet assumer_server
Wndchild: = findjavaswex (WND, 0, 'Shell docobject view', nil );
If wndchild <> 0 then
Begin
Wndchild: = find1_wex (wndchild, 0, 'Internet assumer_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;