private void captureIE() { try { IntPtr hWnd = Win32API.WindowFromPoint(MousePosition); mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)GetHtmlDocumentByHandle(hWnd); if (doc2 != null) { Point point = MousePosition; Win32API.ScreenToClient(hWnd, ref point); IHTMLElement element = doc2.elementFromPoint(point.X, point.Y); A : if (element != null && element.tagName == "IFRAME") { Console.WriteLine("\r\n------IFRAMEInfo----"); Console.WriteLine("X:" + point.X + "Y:" + point.Y); Console.WriteLine("L:" + element.offsetLeft.ToString() + "T:" + element.offsetTop.ToString()); var xx = point.X - element.offsetLeft; var yy = point.Y - element.offsetTop; point = new Point(xx, yy); Console.WriteLine("xx:" + xx + "yy:" + yy); var iframe = (element as IHTMLFrameBase2).contentWindow; element = iframe.document.elementFromPoint(xx, yy); goto A; } if (element != null) { //Console.WriteLine($"\r\nelement.offsetHeight:{element.offsetHeight}\r\nelement.offsetWidth:{element.offsetWidth}\r\n element.offsetLeft:{element.offsetLeft}\r\n element.offsetTop:{element.offsetTop}"); readIEElement(element); } } } catch (Exception e) { Console.WriteLine(e.Message); //MessageBox.Show("发生了一些错误:" + e.Message); } }
private void captureIE() { try { IntPtr hWnd = Win32API.WindowFromPoint(MousePosition); mshtml.IHTMLDocument2 doc2 = (mshtml.IHTMLDocument2)GetHtmlDocumentByHandle(hWnd); if (doc2 != null) { Point point = MousePosition; Win32API.ScreenToClient(hWnd, ref point); IHTMLElement element = doc2.elementFromPoint(point.X, point.Y); readIEElement(element); } } catch (Exception e) { MessageBox.Show("发生了一些错误:" + e.Message); } }