110,536
社区成员
发帖
与我相关
我的任务
分享
public static string GetTabHtml(string theUrl)
{
shellWindows = new ShellWindowsClass();
string tabHtml = "";
foreach (SHDocVw.WebBrowser tab in shellWindows)
{
if (theUrl == tab.LocationURL)
{
HTMLDocument currentTab = tab.Document as mshtml.HTMLDocument;
tabHtml = currentTab.body.outerHTML;
}
}
return tabHtml;
}
[DllImport("user32.dll")]
extern static IntPtr GetForegroundWindow();
private void Form1_Load(object sender, EventArgs e)
{
SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();
string filename;
int a = shellWindows.Count;
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filename.Equals("iexplore"))
{
Console.WriteLine("Web Site : {0}", ie.LocationURL);
mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2;
IntPtr activeHwnd = GetForegroundWindow();
if (htmlDoc != null)
{
if (ie.HWND == activeHwnd.ToInt32())
{
textBox1.Text = htmlDoc.body.outerHTML;
ie.Refresh();
}
}
}
}
}
string tmp = GetTabHtml(URL.ToString());
if(tmp != null || tmp != "")
{
string empty = tmp.Trim();
if (empty != "")
{
IntPtr activeHwnd = GetForegroundWindow();
if(doc != null )
{
if (ie.HWND == activeHwnd.ToInt32())
{
textBox1.Text = doc.body.outerHTML;
ie.Refresh();
}
}
}