The main use is the MSAA (Microsoft Active Accessibility) function: Objectfromlresult, which is defined in the dynamic link library Oleacc.dll.
Uses SHDocVw, MsHtml, ActiveX;
type
Tobjectfromlresult = function (lresult:lresult; const IID:TIID; Wparam:wparam; Out pobject): HRESULT; stdcall;
functionGetiefromhwnd (Whandle:hwnd; var ie:iwebbrowser2): HRESULT;
var
Hinst:hwnd;
lres:cardinal;
Msg:integer;
Pdoc:ihtmldocument2;
Objectfromlresult:tobjectfromlresult;
begin
Result: = S_FALSE;
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;
To invoke the example, the following code quickly closes all open ie windows:
procedureTform1.button1click (Sender:tobject);
var
Hcurwindow, Hmainwnd, Htabwnd, Hcldwnd:hwnd;Window handle
WINCLSNAME:ARRAY[0..255] of Char;
Ie1:iwebbrowser2;
begin
Hcurwindow: = GetWindow (Handle,gw_hwndfirst);Gets the handle of the first window
While hcurwindow<>0 do
Begin
GetClassName (Hcurwindow, @WinClsName, 255);
If String (winclsname) = ' IEFrame ' Then
Begin
Hmainwnd: = Hcurwindow;
Hcldwnd: = Hcurwindow;
Htabwnd: = 0;
RepeatLoop Find all Tabs
Htabwnd: = FindWindowEx (Hmainwnd, Htabwnd, ' Frame Tab ', nil);
If Htabwnd <> 0 then Hcldwnd: = FindWindowEx (htabwnd, 0, ' Tabwindowclass ', nil);
If Hcldwnd <> 0 then Hcldwnd: = FindWindowEx (hcldwnd, 0, ' Shell docobject View ', nil);
If Hcldwnd <> 0 then Hcldwnd: = FindWindowEx (hcldwnd, 0, ' Internet explorer_server ', nil);
If Hcldwnd <> 0 Then if Getiefromhwnd (Hcldwnd, IE1) = S_OK ThenGet IWebBrowser2
Begin
IE1. Quit; //Close IE, can also perform other operations, hehe
End
Until Htabwnd = 0;
End
Hcurwindow:=getwindow (Hcurwindow,gw_hwndnext); //Get handle to the next window
End
End
Delphi access to web interface via IE Window handle (IWebBrowser2)