функция GetHTMLElementUnderneath возвращает HTML тэг, который находится в заданных координатах. При необходимости функция анализирует фреймы.
Код | function GetFrameIndex(gFrame:IHTMLElement):integer; var i:integer; iColl:IHTMLElementCollection; tEl:IHTMLElement; doc:IHTMLDocument2; begin result:=-1; doc:=gFrame.document as IHTMLDocument2; iColl:=doc.all.tags('FRAME') as IHTMLElementCollection; for i:=0 to iColl.length-1 do begin inc(result); tEl:=IDispatch(iColl.item(i,0)) as IHTMLElement; if gFrame.sourceIndex=tEl.sourceIndex then exit; end;//for iColl:=doc.all.tags('IFRAME') as IHTMLElementCollection; for i:=0 to iColl.length-1 do begin inc(result); tEl:=IDispatch(iColl.item(i,0)) as IHTMLElement; if gFrame.sourceIndex=tEl.sourceIndex then exit; end;//while result:=-1; end;//GetFrameIndex
function GetFrameDoc(gDoc:IHTMLDocument2;ind:integer):IHTMLDocument2;overload; var Container : IOleContainer; Browser : IWebBrowser2; Unknown : IUnknown; Enumerator : ActiveX.IEnumUnknown; Fetched: Longint; begin result:=nil; if not (Supports(gdoc, IOleContainer, Container)) then exit; if Container.EnumObjects(OLECONTF_EMBEDDINGS, Enumerator) <> S_OK then exit; Enumerator.Skip(ind); if Enumerator.Next(1, Unknown, @Fetched) <> S_OK then exit; try if Supports(Unknown, IWebBrowser2, browser) then result:=Browser.Document as IHTMLDocument2; except end;//except silencer end;//GetFrameDoc
function GetFrameDoc(gFrame:IHTMLElement):IHTMLDocument2;overload; var ind:integer; begin result:=nil; ind:=GetFrameIndex(gFrame); if ind=-1 then exit; result:=GetFrameDoc(gFrame.document as IHTMLDocument2,ind); end;//GetFrameDoc
function GetHTMLElementUnderneath(gX,gY:integer;gWB:TWebBrowser):IHTMLElement; var TheDoc:IHTMLDocument2; cP:TPoint; begin result:=nil; if not IsHTMLContent(gWB) then exit; cP:=gWB.ScreenToClient(Point(gX,gY)); if Assigned(gWB.ControlInterface) then TheDoc:=gWB.ControlInterface.Document as IHTMLDocument2; if not Assigned(TheDoc) then exit; result:=TheDoc.ElementFromPoint(cP.X,cP.Y); while Assigned(result) and ((result.tagName='FRAME') or (result.tagName='IFRAME')) do begin TheDoc:=GetFrameDoc(result); if not Assigned(TheDoc) then exit; cP.X:=cP.X-GetElementLeft(result); cP.Y:=cP.Y-GetElementTop(result); result:=TheDoc.ElementFromPoint(cP.X,cP.Y); end;//while end;//GetHTMLElementUnderneath
|
|