//Get Frame public mshtml.HTMLWindow2 GetFrameByName(mshtml.HTMLWindow2 webApp, string name) { mshtml.HTMLDocument Doc = (mshtml.HTMLDocument)webApp.document; int length = System.Convert.ToInt32(Doc.frames.length); mshtml.FramesCollection frames = Doc.frames; object i = null; for (i = 0; (int)i <= length - 1; i = (int)i + 1) { mshtml.HTMLWindow2 frm = (mshtml.HTMLWindow2)(frames.item(i)); if (frm.name == name) { return(frm); } } for (i = 0; (int)i <= length - 1; i = (int)i + 1) { mshtml.HTMLWindow2 frm = (mshtml.HTMLWindow2)(frames.item(i)); object wd = GetFrameByName(frm, name); if (wd != null) { return((mshtml.HTMLWindow2)wd); } } return(null); }
//Get Frame public mshtml.HTMLWindow2 GetFrameByName(ref SHDocVw.InternetExplorerMedium WebOrWindow, string name) { SleepAndWaitComplete(WebOrWindow); try { mshtml.HTMLDocument Doc = (mshtml.HTMLDocument)WebOrWindow.Document; int length = System.Convert.ToInt32(Doc.frames.length); mshtml.FramesCollection frames = Doc.frames; mshtml.HTMLWindow2 frm = default(mshtml.HTMLWindow2); //Object 必要、 frames.item(i) iはInertger時 エラー object i = null; for (i = 0; (int)i <= length - 1; i = (int)i + 1) { //frm = if (((mshtml.HTMLWindow2)(frames.item(i))).name == name) { return((mshtml.HTMLWindow2)(frames.item(i))); } } object wd = null; for (i = 0; (int)i <= length - 1; i = (int)i + 1) { frm = (mshtml.HTMLWindow2)(frames.item(i)); wd = GetFrameByName(frm, name); if (wd != null) { return((mshtml.HTMLWindow2)wd); } } } catch (Exception) { } return(null); }
//Sleep And Wait IE Complete public void SleepAndWaitComplete(SHDocVw.InternetExplorerMedium webApp, int tmOut = 100) { Sleep5(100); for (int i = 0; i <= 10; i++) { while (!(webApp.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE && !webApp.Busy)) { System.Windows.Forms.Application.DoEvents(); Sleep5(System.Convert.ToInt32((double)tmOut / 10)); i = 0; } while (!(((mshtml.HTMLDocument)webApp.Document).readyState.ToLower() == "complete")) { System.Windows.Forms.Application.DoEvents(); Sleep5(System.Convert.ToInt32((double)tmOut / 10)); i = 0; } try { mshtml.HTMLDocument Doc = (mshtml.HTMLDocument)webApp.Document; int length = System.Convert.ToInt32(Doc.frames.length); mshtml.FramesCollection frames = Doc.frames; for (int j = 0; j <= length - 1; j++) { mshtml.HTMLWindow2 frm = (mshtml.HTMLWindow2)(frames.item(j)); while (!(frm.document.readyState.ToLower() == "complete")) { System.Windows.Forms.Application.DoEvents(); Sleep5(1); } } } catch (Exception) { } } }